End time of the crontab job… here is a solution to the problem.
End time of the crontab job
I intend to run the snoop command every 5 minutes between 20:00 and 23:00
, but I don’t know how to end in the last 5 minutes (22:55 to
23:00
).
Can you help me with this?
Listen to commands:
FILE=vitrin_`date +%Y%m%d%H%M`.cap
kill -9 `pgrep snoop`
snoop -x0 -d e1000g0 -o /export/home/vitrin/$FILE
Scheduled tasks:
0,5,10,15,20,25,30,35,40,45,50,55 20,21,22 * * * /export/home/snoop.sh
Solution
Instead of terminating your SNOOP
on the next cron run (and possibly some other unrelated), you can do it in a way like timeout
from coreutils Run it from scratch under the supervision of tools like that. At least under Linux you almost certainly already have it, unless your coreutils are old.
timeout 5m snoop ...
status=$?
[ $status -eq 124 ] && exit 0
exit $status
If you really need SIGKILL
timeout
, there is a --signal
option.
If a running command is terminated by a timeout, the exit status is set to 124. In your case, you seem to want to ignore it, eg. Just like the example above.