免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1426 | 回复: 2
打印 上一主题 下一主题

shell中运行子shell的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-05 12:17 |只看该作者 |倒序浏览

  1. $cat Check_RunLogError.sh
  2. #!/bin.sh
  3. LogPath="/miscfile/misc16/misclog/tlog/tmp_run.log"
  4. Tail_RunLog()
  5. {
  6. cat >TailRunLog.sh<< EOF
  7. #!/bin/sh
  8. tail -f $LogPath |grep "InMsg,resp," >>/tmp/TailLog.tmp &
  9. Tail_Flag_Old=\`head -1 $LogPath |awk -F, '{print \$1}'\`
  10. while true;do
  11.         Tail_Flag_New=\`head -1 $LogPath |awk -F, '{print \$1}'\`
  12.         if [ "\$Tail_Flag_New" != "\$Tail_Flag_Old" ];then
  13.                 ps -ef|grep "tail -f $LogPath"|grep -v grep|awk '{print \$2}'|xargs kill
  14.                 tail -f $LogPath |grep "InMsg,resp," >>/tmp/TailLog.tmp &
  15.         fi
  16.         sleep 1
  17. done
  18. EOF
  19. chmod +x TailRunLog.sh
  20. ./TailRunLog.sh &
  21. }


  22. Check_RunLogError()
  23. {
  24.         if [ -z "`ps -ef|grep 'TailRunLog.sh'|grep -v grep`" ];then
  25.                 Tail_RunLog
  26.         fi
  27. }
  28. Check_RunLogError
  29. $./Check_RunLogError.sh
  30. head: cannot open `/miscfile/misc16/misclog/tlog/tmp_run.log' for reading: No such file or directory
  31. usage: kill [ -s signal | -p ] [ -a ] pid ...
  32.        kill -l [ signal ]
  33. 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是没被写入文件的
难道是环境的问题,有什么解决发放没?

论坛徽章:
0
2 [报告]
发表于 2009-05-05 12:34 |只看该作者
找到解决办法了
nohup ./TailRunLog.sh &

论坛徽章:
0
3 [报告]
发表于 2009-05-05 12:35 |只看该作者
呵呵
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP