- 论坛徽章:
- 0
|
- $cat Check_RunLogError.sh
- #!/bin.sh
- LogPath="/miscfile/misc16/misclog/tlog/tmp_run.log"
- Tail_RunLog()
- {
- cat >TailRunLog.sh<< EOF
- #!/bin/sh
- tail -f $LogPath |grep "InMsg,resp," >>/tmp/TailLog.tmp &
- Tail_Flag_Old=\`head -1 $LogPath |awk -F, '{print \$1}'\`
- while true;do
- Tail_Flag_New=\`head -1 $LogPath |awk -F, '{print \$1}'\`
- if [ "\$Tail_Flag_New" != "\$Tail_Flag_Old" ];then
- ps -ef|grep "tail -f $LogPath"|grep -v grep|awk '{print \$2}'|xargs kill
- tail -f $LogPath |grep "InMsg,resp," >>/tmp/TailLog.tmp &
- fi
- sleep 1
- done
- EOF
- chmod +x TailRunLog.sh
- ./TailRunLog.sh &
- }
- Check_RunLogError()
- {
- if [ -z "`ps -ef|grep 'TailRunLog.sh'|grep -v grep`" ];then
- Tail_RunLog
- fi
- }
- Check_RunLogError
- $./Check_RunLogError.sh
- head: cannot open `/miscfile/misc16/misclog/tlog/tmp_run.log' for reading: No such file or directory
- usage: kill [ -s signal | -p ] [ -a ] pid ...
- kill -l [ signal ]
- tail: cannot open `/miscfile/misc16/misclog/tlog/tmp_run.log' for reading: No such file or directory
复制代码
/miscfile/misc16/misclog/tlog/tmp_run.log 不断被写入,且2分钟后会被MV
我的实验环境是这样的
while true;do cat tmp.log >>tmp_run.log ;sleep 1;done
while true ;do mv tmp_run.log tmp.log;sleep 120;done
但是单独运行生成的TailRunLog.sh是可以成功运行的
但在Check_RunLogError.sh的子环境中,就报上面的错误,而且/tmp/TailLog.tmp是没被写入文件的
难道是环境的问题,有什么解决发放没? |
|