The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find last sunday (date) using perl? deepakwins UNIX for Dummies Questions & Answers 3 07-18-2008 01:06 PM
Searching for a file, with name Last Sunday through Saturday rejirajraghav Shell Programming and Scripting 0 03-19-2008 12:55 AM
How to check for Saturday or Sunday harpreetanand SUN Solaris 5 08-11-2007 01:31 PM
different between soft reboot and hard reboot seelan3 SUN Solaris 3 09-20-2006 11:12 PM
Date - Last Sunday thru Saturday skymirror Shell Programming and Scripting 2 12-12-2005 10:18 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-28-2008
Registered User
 

Join Date: Jul 2007
Posts: 53
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.
Reply With Quote
Forum Sponsor
  #2  
Old 03-28-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
As it happens, we covered that recently. Here:

File extension search and copy

The thread is rather meandering but around message #10 are a few posts on this particular topic.
Reply With Quote
  #3  
Old 03-28-2008
System Shock's Avatar
Registered User
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 395
... 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
Reply With Quote
  #4  
Old 04-03-2008
Registered User
 

Join Date: Jul 2007
Posts: 53
Quote:
Originally Posted by System Shock View Post
... 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.
Reply With Quote
  #5  
Old 04-03-2008
Registered User
 

Join Date: Mar 2008
Location: Toronto, Canada
Posts: 66
Clever!

And maybe you only need just the following one line at the start of your script
Code:
[[ $(date '+%e') -gt 7 ]] && exit
Reply With Quote
  #6  
Old 04-04-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
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>
Reply With Quote
  #7  
Old 04-04-2008
Registered User
 

Join Date: Mar 2008
Location: Toronto, Canada
Posts: 66
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>
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0