- 论坛徽章:
- 0
|
本帖最后由 david0 于 2016-09-18 10:17 编辑
求助高手指点,下面的程序如何修改。
功能:在Oper_List.txt文件是运维人员每天的排班信息,要求通过定时脚本Oper_update.sh,根据Linux系统日期和Oper_List.txt中每天的排班信息,对数据库表的OperName和OperPhone字段进行定时更新(每天8:30执行定时任务)。
下面是运维人员的排班信息(用TAB隔开):
#more Oper_List.txt
北京分公司 张三 2016-09-15 8:30~8:29 18711111111
北京分公司 李四 2016-09-16 8:30~8:29 18711111112
北京分公司 王五 2016-09-17 8:30~8:29 18711111113
北京分公司 赵六 2016-09-18 8:30~8:29 18711111114
北京分公司 范三 2016-09-19 8:30~8:29 18711111115
北京分公司 张四 2016-09-20 8:30~8:29 18711111116
#more Oper_update.sh
#!/bin/sh
#########更新运维工程师信息########
source /home/operuser/.profile
tempdate=`date +%Y-%m-%d`
i=1
#定义每列的取值,分别对应机构名称,运维人员姓名,值班日期,值班时间,手机号
orgname=`awk '{if(NR=='"$i"') print $1}' /backup/shell/crontab/Oper_List.txt`
dutyname=`awk '{if(NR=='"$i"') print $2}' /backup/shell/crontab/Oper_List.txt`
dutydate=`awk '{if(NR=='"$i"') print $3}' /backup/shell/crontab/Oper_List.txt`
dutytime=`awk '{if(NR=='"$i"') print $4}' /backup/shell/crontab/Oper_List.txt`
mobile=`awk '{if(NR=='"$i"') print $5}' /backup/shell/crontab/Oper_List.txt`
#根据当天系统日期,对运维人员姓名OperName和手机号OperPhone进行更新
/opt/nmsoft/bin/nco_sql -server testdb -username operuser -password oper1234 <<EOF >/tmp/OperList.log
update Branch.Oper_tab set OperName='$dutyname', OperPhone='$mobile' where FirstOrgName like 'Beijing' and to_char(getdate,'yyyy-MM-dd') like '$tempdate' and OperName not like '$dutyname';
go
quit
EOF
举例:
定时任务每天8:30执行Oper_update.sh脚本,根据当前系统日期,然后从Oper_List.txt文件中找到日期为2016-09-16这一行,抽取相应的列信息,第2列、第5列
北京分公司 李四 2016-09-16 8:30~8:29 18711111112
再执行nco_sql命令进行表字段更新的操作:
update Branch.Oper_tab set OperName='李四', OperPhone='$18711111112' where FirstOrgName like 'Beijing' and to_char(getdate,'yyyy-MM-dd') like '2016-09-16';
|
|