LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-31-2010, 07:28 AM   #1
pajoryan_red
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
Using a cron job to automate a red hat shutdown


I have added the following line to a crontab job on Red Hat:
0 12 22 05 sat /sbin/shutdown -h now

It was supposed to be a once off job to shutdown a red hat box on the 22nd May at 12:00. The job worked fine, the machine shut down. The problem is that it also shut down the machine on the following saturday (29th May).

Am i using the wrong syntax for this cron job?
I just want it to shutdown on the date that i specify and only that date. I dont want the shutdown to re occur.

any help greatly appreciated.
thanks.
 
Old 05-31-2010, 07:59 AM   #2
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Extract from the cron man pages:

Quote:
Notes:

Under dow 0 and 7 are both Sunday.

If both the dom and dow are specified, the command will be executed when
either of the events happen.
e.g.
* 12 16 * Mon root cmd
Will run cmd at midday every Monday and every 16th, and will produce the
same result as both of these entries put together would:
* 12 16 * * root cmd
* 12 * * Mon root cmd
Basically, specifying the day of week and day of month does not mean that your command executes on a specific day of month ONLY. Your cron entry means that this command is executed:

1. On the 22nd day of May
2. On every Saturday.

If you wanted the command to run ONLY on Saturday 22nd May, then you should rather specify:

Code:
0 12 22 05 * /sbin/shutdown -h now
This tells the crond that this command must ONLY run on 12:00 on the 22nd Day of the 5th Month (ie. May); irrespective of what day of the week that date falls on.

Also if you wanted this to happen once off on the 22nd, you could have commented this entry out in the cron and it would not have happened again.
 
Old 05-31-2010, 08:15 AM   #3
pajoryan_red
LQ Newbie
 
Registered: May 2010
Posts: 2

Original Poster
Rep: Reputation: 0
many thanks.
 
Old 05-31-2010, 08:30 AM   #4
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Remember to mark the thread as solved if you're happy with the answer above (under Thread Tools).
 
Old 05-31-2010, 10:25 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Cron is typically used for repeated jobs. If you use
Code:
0 12 22 05 * /sbin/shutdown -h now
will run again on 22 May in the coming years...

Code:
man at
"at" command is a better choice for run-once scheduled jobs.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delaying shutdown while cron job is running bitpicker Linux - General 7 05-19-2009 07:35 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
How to automate ftp in a cron job rust8y Linux - General 4 06-20-2007 09:39 AM
shutdown cron job tapanga Linux - Newbie 1 06-08-2004 01:17 PM


All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration