• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1882
  • Last Modified:

shutdown linux box at same time everyday using crontab

Hi EE.  I have a linux box with fedora 5.  I would like to shut it down at the same time every day.    I have entered the instructions in crontab to point to a script that I have placed in the /etc folder.    the entry in crontab basically says

30 19 * * * sh /etc/netcon/turnoff.sh

turnoff.sh has the entry - 'sudo shutdown -h now'

for some reason this isnt working.  How can I get crontab to shut the machine down everyday?
0
aduhwale
Asked:
aduhwale
2 Solutions
 
sanjoozCommented:
as root, do a crontab -e and add this entry

* 20 * * *     /sbin/shutdown -h now --> shuts down everyday at 8 PM local time
* 19 * * *     /sbin/shutdown -h now --> shuts down everyday at 7 PM local time

0
 
chingmdCommented:
I agree.     You will want to clearn the crontab for your personal user.

run sudo crontab -e

this will run the crontab as root and will not need to sudo portion.
0
 
TintinCommented:
What user is the cronjob for?

Show us the sudo entry.

As pointed out by the previous two posters, better to just have a root cronjob for this task.
0
 
TintinCommented:
BTW, the following entries:

* 20 * * *     /sbin/shutdown -h now --> shuts down everyday at 8 PM local time
* 19 * * *     /sbin/shutdown -h now --> shuts down everyday at 7 PM local time

Would shutdown the server every minute from 19:00-20:00.  This means when it gets shutdown at 19:00, if you powered it back on before 20:00, it would shutdown again.

The correct entries should be:

0 20 * * *     /sbin/shutdown -h now --> shuts down everyday at 8 PM local time
0 19 * * *     /sbin/shutdown -h now --> shuts down everyday at 7 PM local time
0
 
aduhwaleAuthor Commented:
Hey guys!   worked.   I modified it a little.  I placed the command you gave me in a script then pointed crontab to that script. This way I can add more commands to my script , like run the back up , clear folders etc.  
I have split the points between Sanjooz and tintin. Thanks guys
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now