[Trilug-ontopic] CronTab exclusions
Alan Porter
porter at trilug.org
Tue Jan 1 12:20:38 EST 2008
> # Reboot every other Monday morning at 6am.
> 00 6 1-7,15-21 * 1 /sbin/shutdown -r now
>
> So, as written, it actually reboots every Monday AND every
> day of every other week. DOAH!
The solution mentioned earlier -- run a script that checks
the day of the week.
Most of my crontab entries end up being wrapper scripts anyway,
since a lot of times, the command lines ending up being very
long to redirect output to a log file. I put my scripts in a
directory named /root/cron.
This solution is not quite as tidy as day-of-week filtering in
the crontab itself, but it is very effective.
root at copycat:~# crontab -l
# Reboot every other week at 6am.
# Script will only reboot on Mondays.
00 6 1-7,15-21 * * /root/cron/shutdown.sh
root at copycat:~# cat /root/cron/reboot.sh
#!/bin/bash
# Only reboot on Mondays
if [ $(date +%u) -eq 1 ] ; then
/sbin/shutdown -r now > /var/log/reboot.out 2>&1
fi
Alan
.
More information about the Trilug-ontopic
mailing list