shedule monthly reboot on first sunday


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users shedule monthly reboot on first sunday
# 1  
Old 03-28-2008
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.
# 2  
Old 03-28-2008
As it happens, we covered that recently. Here:

https://www.unix.com/unix-advanced-ex...post302178817l

The thread is rather meandering but around message #10 are a few posts on this particular topic.
# 3  
Old 03-28-2008
... 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:
Code:
DATE=$(date '+%e')

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

# 4  
Old 04-03-2008
Quote:
Originally Posted by System Shock
... 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:
Code:
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.
# 5  
Old 04-03-2008
Clever!

And maybe you only need just the following one line at the start of your script
Code:
[[ $(date '+%e') -gt 7 ]] && exit

# 6  
Old 04-04-2008
Schedule monthly reboot every first sunday

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>
# 7  
Old 04-04-2008
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:
Code:
# Monthly reboot scheduled every first Sunday at 9:30PM
30 21 * * 0 /usr/local/<shutdown.script.sh>

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tar archives monthly

Hi, I want to archive files by month, is there anyway of this code looks better? find /tmp/w/ -type f -newermt '2014-01-01' ! -newermt '2014-02-01' | xargs tar -czvf files01.tar find /tmp/w/ -type f -newermt '2014-02-01' ! -newermt '2014-03-01' | xargs tar -czvf files02.tar find... (9 Replies)
Discussion started by: prpkrk
9 Replies

2. Shell Programming and Scripting

help with a script to have monthly sar reports

Hi I am still learning shell scripting, so for complex stuff, I need help. I would like to have a script that produces sar monthly reports, so that I can produce a graph from it! The idea is to use /var/adm/sa/<dir of sa files>Looking to hear from you. regards (4 Replies)
Discussion started by: fretagi
4 Replies

3. What is on Your Mind?

Monthly Salary in India for Web Programmer?

Anyone know the normal and average monthly salary (and hourly wage for part time) for a solid Web Development in India? Basic requirements. LAMP (Linux, Apache, MySQL, PHP), HTML, CSS, Javascript. vBulletin a plus, but not necessary. Anyone have any idea? (5 Replies)
Discussion started by: Neo
5 Replies

4. UNIX for Advanced & Expert Users

Autosys JOB on monthly basis

Dear All, Can someone tell me how do I setup autosys job where it needs to execute on monthly basis that too on 1st day of the month. Thanks. (3 Replies)
Discussion started by: shahnazurs
3 Replies

5. Shell Programming and Scripting

Execution problem with crom for monthly

I have to setup cron job for monthly and the month may be 30 or 31 Thanks, (2 Replies)
Discussion started by: lakshmikant
2 Replies

6. Post Here to Contact Site Administrators and Moderators

monthly membership??

Hi, Do we have monthly membership (VIP) in our forum? if not, do we have any plans for it? Regards, (1 Reply)
Discussion started by: clx
1 Replies

7. Shell Programming and Scripting

monthly calculation

pls can anyone help me with this script, the script is below, i need the script to get the previous month result every new month , the problem is that the loop has to be automated to always calculate for previous month . a=`date "+%Y"` #this year to be used b=$(date "+%Y%m" --date='49 days... (6 Replies)
Discussion started by: neyo
6 Replies

8. Solaris

different between soft reboot and hard reboot

Hi Guru's Can any want here could explain to me the different between soft reboot and hard reboot . Best Regards Seelan (3 Replies)
Discussion started by: seelan3
3 Replies
Login or Register to Ask a Question