shedule monthly reboot on first sunday

Hello,
I looked around but can't find a clear answer on this. Is there a way to shedule a box to reboot say on the first sunday of every month? Does it involve the cron.monthly file somehow, I googled and can't find how those cron.weekly, cron.monthly files function... This would be for Suse 9 boxes. Thanks.

As it happens, we covered that recently. Here:

http://www.unix.com/unix-advanced-expert-users/58363-file-extension-search-copy.html\#post302178817l

The thread is rather meandering but around message #10 are a few posts on this particular topic.

... there is a much easier way to do that, which doesn't involve any other files.

Schedule your script to run every Sunday.

Now, the date of any first Sunday of the month (or any first ***day of the month for that matter ) will always fall between the 1st of the month and the 7th of the month, since there are only 7 days on a week.

So, the first Sunday of the month can only be the 1st, 2nd, 3rd, 4th, 5th, 6th, or .the 7th.

So, at the beginning of your script, you are going to make a variable that will be equal to the extracted day number from the date command, and add a small if statement, and if that number is higher than 7, you script should exit.

Like this:

DATE=$(date '+%e')

if (( ${DATE} > 7 )); then
   exit 0
else
   run your script
fi

Thanks, that script is probably the best solution, I was just hoping cron had something in it to do this but I guess not. Thanks for all help.

Clever!

And maybe you only need just the following one line at the start of your script

[[ $(date '+%e') -gt 7 ]] && exit

This is probably what you're looking for. Input this in cron, provided that you have a shutdown script already. Change the time if you wish.

# Monthly reboot scheduled every first Sunday at 9:30PM
30 21 1-7 * * test `date +\%a` = Sun && /usr/local/<shutdown.script.sh>

I would say you don't need to schedule it for every day and test to run it on Sundays only. Just schedule it to run on Sundays (i.e. the fifth column being ZERO) as:

# Monthly reboot scheduled every first Sunday at 9:30PM
30 21 * * 0 /usr/local/<shutdown.script.sh>

My search end here...
Hope this will do :b:

30 21 1-7 * sun /usr/local/<restart.script.sh>

Please ignore "./hari.sh" post. The cron will fire on every day 1-7 AND on every Sunday. There is a similar example in "man crontab".

The best technique has already been described. i.e. Run the cron on days 1-7 and check whether it is a Sunday.