如何在指定时间后终止shell脚本

时间:2014-10-13 07:15:58

标签: shell cron ksh

我有一个shell脚本检查文件state.txt,如果state.txt为空,则删除fit.bin。 我在凌晨2点cron这个,我希望脚本在上午8点停止,不管state.txt的值是什么,有什么想法吗?

#!/usr/bin/ksh


while true; do


if [[ -s ~/state.txt ]] ; then

echo

else

rm ~/fit.bin

exit

fi ;


sleep 961

done

exit

2 个答案:

答案 0 :(得分:1)

这是"模型":

#!/bin/bash

while true
do
    NOW=`date '+%H%M'`
    echo "Time is now: $NOW"
    sleep 3
    if [ $NOW -ge 800 ]
    then
        echo "Bye bye!"
        exit 0
    fi
done

答案 1 :(得分:0)

#!/bin/bash
while [ $( date '+%H%M' ) -lt 800 ]
 do
   [ -s "~/state.txt" ] && rm ~/fit.bin

   sleep 961
 done
相关问题