Coder of Salvation™ — programming / opensource / console / minimal
Conditional Cron
Problem
Cron is our friend, but only programmed to be loyal & faithfull. In some cases we want cron to do something..and sometimes not (condition).
Solution
Instead of writing/seperating crontasks, make one smart cronjob using the date-cmd.
Example
0 0 * * * /home/username/somecmdA >> .cron.log
0 1 * * * /home/username/somecmdB >> .cron.log
0 0 1 * * /home/username/somecmdC >> .cron.log
What if all commands are doing the same stuff..seperation can be good and bad.
Possible solution
0 0 * * * /home/username/somecmd >> .cron.log
and then in somecmd:
# do common everyday stuff
echo "doing everyday stuff"
if [ $(date +%a) == "Tue" ] ; then cleanuplogs; fi
Demo
comments powered by
All rights reserved by Leon van Kammen under this license