Cron job every 4th Saturday

I have a 'ditto' command that I'd like to run every 4th Saturday.

Can anyone advise how I should set crontab?

G5/dual 2ghz/2.5gb RAM, Mac OS X (10.4.7)

Posted on Oct 1, 2006 8:51 AM

Reply
3 replies

Oct 1, 2006 11:00 AM in response to David McMillan

In short, you can't do this in one step.

You might think you can do something like

0 0 22-28 * 6 /path/to/ditto blah blah blah


which most people would interpret as run at midnight on every day between the 22nd and 28th of the month that happens to be a Saturday, but cron actually interprets this as 'run every day between 22-28 and also on Saturdays' which isn't what you want.

The easiest solution is to write a wrapper for your ditto command. Have your crontab call your script on one of the parameters (e.g. every day between the 22nd and the 28th) and the first thing your script does is check if the day is the other condition (e.g. Saturday). If it isn't, it gracefully exits.

This wrapper script could be as simple as:

#!/bin/sh

DAY="`date +%u`"
if [ "${DAY}" = "6" ] ; then
echo "Saturday - time to backup"
# ditto command goes here
else
echo "Not Saturday - do nothing""
fi

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Cron job every 4th Saturday

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.