Having put together some incremental backup software, I was very annoyed to find that cron wasn't running the /etc/daily script because cron doesn't run while my computer is asleep, and my computer is always asleep at 3:15am when /etc/daily is set to be run.
So, I made a very simple perl script that fixes this problem. It checks the modification times for the daily, weekly, and monthly log files. If they are more than a day, week, or month old, respectively, it runs the appropriate commands.
To learn more, read on...
There are two steps:
First save the text below as a perl script in a good place, I chose to call it /usr/local/bin/crontastic.pl. You can use something like pico or emacs in the terminal or an app like BBEdit that can save with Unix line endings:
#!/usr/bin/perlMake sure that the script is executable by, by typing this in the terminal:
system "sh /etc/daily 2>&1 | tee /var/log/daily.out | mail -s "`hostname` daily output" root"
if !-e '/var/log/daily.out' or -M '/var/log/daily.out' > 1;
system "sh /etc/weekly 2>&1 | tee /var/log/weekly.out | mail -s "`hostname` weekly output" root"
if !-e '/var/log/weekly.out' or -M '/var/log/weekly.out' > 7;
system "sh /etc/monthly 2>&1 | tee /var/log/monthly.out | mail -s "`hostname` monthly output" root"
if !-e '/var/log/monthly.out' or -M '/var/log/monthly.out' > 30;
chmod a+x /usr/local/bin/crontastic.plNow, adjust your /etc/crontab file. First comment out each of the daily, weekly, and monthly lines, by putting a "#" at the beginning of those line so that cron won't try to run those lines anymore. Second, tell cron to run the crontastic script every half hour (I figure everyone's computer will be awake for at least a half hour at a time):
*/30 * * * * root /usr/local/bin/crontastic.plAnd there you have it.
now=`date "+%A %B %e, %l:%M %p"`Note that those are back-tics on the now=... lines and not single quotes.
/usr/bin/osascript <<EOF
say "Running cron monthly on $now"
EOF
Mac OS X Hints
http://hints.macworld.com/article.php?story=20020309203951180