shutdown linux box at same time everyday using crontab

Posted on 2007-10-08
Last Modified: 2013-12-16
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/ has the entry - 'sudo shutdown -h now'

for some reason this isnt working.  How can I get crontab to shut the machine down everyday?
Question by:aduhwale
    LVL 9

    Accepted Solution

    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

    LVL 9

    Expert Comment

    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.
    LVL 48

    Expert Comment

    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.
    LVL 48

    Assisted Solution

    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
    LVL 2

    Author Comment

    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

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
    I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now