linux - 计时器检查文件末尾 bash shell

标签 linux bash shell

我使用的代码基本上是在计算完成后重新启动计算。该代码运行良好。但我想即兴编写代码。现在它在定时器函数 sleep 上运行。它从不检查文件末尾。因此,无论上一个作业如何,它都会等待 22 分钟才能提交下一个作业。所以我想以这样的方式更改代码,它每隔一分钟检查文件末尾是否有日志文件中的关键字“程序结束”并提​​交下一个作业。如果您有任何想法,请给我留言...

<小时/>

同时(1)

<小时/>

#sleep X 秒/分钟

    $SLEEP 22m
    #cut JobID into peeces:
    #e.g.: 31380.chic1i20.informatik.tu-chemnitz.de Info: Your job definition is checked against CHiC policies. --> 31380.chic1i20
    #set JOBnr = `echo $JOBID | $CUT -c-15`
    set JOBnr = `echo $JOBID | $CUT -d " " -f1 | $CUT -d "." -f-2`
    $QSTAT -nu "$USER" > .qstat_outfile
    if ( "$?" ) then
            echo "autorestart: qstat error"
            $CAT .qstat_outfile
            continue
    endif

最佳答案

试试这个:

UNWRITTEN=0
while [ $UNWRITTEN -eq 0 ]; do
 token=$(tail -n 2 .qstat_outfile)
 echo $token
 if [[ $token == "End of program" ]]
 then
     echo "autorestart..."
     UNWRITTEN=1
 fi
 sleep 60
done

说明:

  • 程序不断循环,直到在日志文件末尾找到正确的行。然后它会重新启动计算并退出。
  • tail -n 2 读取最后两行(如果“程序结束”后有换行符,则实际上是最后一行。您可能需要在系统上将其调整为 -n 1。)

关于linux - 计时器检查文件末尾 bash shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21387107/

相关文章:

linux - 为什么在线CPU的数量等于n-1,而n是CPU的总数?

linux - bash --redirect 输出到日志文件(名称中包含日期)

unix - 比较两个内容有很多文件的文件夹

arrays - Bash 数组分组元素

linux - Unix/Linux,删除行中的注释

c - C中同时独立执行两个函数

bash - 替换上一个 bash 命令中所有字符串的快捷方式

bash - sed 失败并出现 "unknown option to ` s'"错误

bash - 启用登录提示后,我没有 shell 颜色

xml - 编辑xml文件shell脚本