Saturday, April 16, 2011

Use At to run repeated task

Following is an example, schedule.sh, to run check_process.sh script at /home/pwong every 3 minutes within 12 hours period.


WorkDir=/home/pwong

if [ ! -f off_time ]; then
date --date="+12 hours" +"%k" > off_time
fi

if [ `date +%k` -eq `cat off_time` ]; then
rm off_time
exit 1
fi

sleep 60

cd $WorkDir

at -f schedule.sh +3 minutes

check_process.sh

exit 0

No comments: