Howto: Shutdown Linux Box Automatically

last updated in Categories CentOS, Debian Linux, Gentoo Linux, Howto, Linux, Suse Linux, Sys admin, Tips, UNIX

You may wonder – why should I shutdown the Linux box automatically? It depends upon your situation. For example, you are downloading couple of tar balls and you want to go home early. You can schedule a job to shutdown Linux after downloading is completed. Linux/UNIX/BSD/OS X comes with at and cron commands to automate task. Almost all common task can be automated using at command.


Common Tasks For at Command

  1. Shutdown/reboot the system
  2. Email yourself files
  3. Send birthday remainders


  • at– Execute a task at a specific time. For example, shutdown computer, send birthday remainder etc. Useful to schedule one job at a time or a single future event.
  • cron รขโ‚ฌโ€œ If you want to shutdown Linux box automatically everyday 8 pm then you need to use cron instead of at command (see below for examples). Useful to schedule recurring events or daily events such as backup data, or check system security etc.

at Command Examples

Let us see how to shutdow a Linux automatically at 8 pm, type the command at 8pm and press [enter] key, then type halt followed by enter key. To save your job press CTRL+D.

# at 8pm
Sample outputs:

at> halt

(Press CTRL+D)

Try out the following utilities:

  • atq – List the current at jobs pending.
  • atrm – Used to remove pending at jobs.

at command accept fairly complex time specifications, for example:
Run job at 6am on monday:

at 6am monday

Run job in 5 minutes time:

at now + 5 minutes

Run job at 4pm but 3 days later:

at 4pm + 3 days

Run job at 10am on 31st July:

at 10am Jul 31

See the file /usr/share/doc/at/timespec for complete time specifications and read man pages of at, atq, atrm. Make sure you have atd service running, if not start it using the following command:
# /etc/init.d/atd start

Linux Cron job to Shutdown Linux server/Desktop system

First, login as the root user and at a shell prompt type crontab -e command so that you can add cronjob:

# crontab -e


# crontab -e -u root

Append the following entry to it to shutdown box at 20:00 hrs [24 hour close format]:

0 20 * * * /sbin/shutdown -h now

Save and close the file.


  • man pages crond, crontab, at

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


30 comment

  1. Thanks for explanation! Can you tell me what is command for just restarting system? By the way, do I have to always put this commands to root or I can also make cron from my account? (sorry, I am quite new in all this..)

  2. I have to shutdown the ubuntu server at midnight but before shutdown the user get 5 minites before interrupt and if the user have permission to discard the shutdown and continue if working

  3. I personally wouldn’t schedule a shutdown if i was downloading a few tarballs and the system needed to be off when it was complete, unattended.
    what if the speed decreases and it doesn’t finish in time?
    Sure, you could expect it to take long and give it lots of time… But what if it gets done early, wouldn’t it be better if it shut down after it was complete, and not wait for the set time?
    best to do something like this, chain commands. so you tell it to download the file and then when its done, shutdown.
    wget && halt
    note: it has to be double & signs. single one will cause both commands to execute at the same time. double causes it to wait for the first one to exit (clean exit or not) before continuing.
    i personally would probably use more along the lines of
    wget 2>/home/kai/wget.log && halt
    so level 2 outputs (errors) are logged. if the file stopped downloading before it was done, i would then know why by reading the output of wget.log

    scheduled shutdowns with at or cron are better for just having a system shutdown _nomatter what_ at said time. if you want your tasks to finish first, chain them.

  4. Thank u for information. I have one RHAS4 server.

    For this morning 8 am it should switched on and late night 11 pm it should shut down automatically. Using crontab we can easily shut down the system. But switch on and shutdown the linux system in different time , i could not find any commands or script.

    please reply

  5. @ saroj Waking up the computer is beyond the OS, its at the BIOS Level and needs an ATX Power supply too.

    Some BIOS s dont have that capability (Old/some OEM)

    but if found its usually under power management.

  6. I didn’t come across usage of shutdown but I have seen examples of user logged off from a machine at particular time. Like in computer training institutes, they used to fix machines for users for a certain duration of time. User comes and uses available machine and once his or her time gets over, it logs off.

  7. Thanks! I was having trouble wrapping my head around the crontab thing. This showed how to do it (and by extension, how it works).

  8. Thank you,

    untill now didn’t need crontabs, coming from VMS I could not get a hold on this crontab, since this Howto I understand at last, I have read loads of internetsites, man pages, books about it. I must say how can something so simple be described so complex.
    I will visit your website more often!


  9. excuse me!
    i am doing project in university i am understanding about linux but i don’t know it
    who i know it can you help me
    and who can i have document about centos , install dns and public mail dns

  10. Its really Good, simple & useful information. i would like to learn useful admin level command from this website or any. Please link me if you have some more stuff like this. …. Thankss.

    1. about shutting down another machine.

      You can do it with ssh.

      First of all. create a script in the machine you want to shutdown. Giving the instructions to shutdown.
      Test it.

      Now you can type the instruction:

      ssh “name/ip of the other machine name-of-the-script”

      and … that’s all.

      of course you can put the instruction for ssh in your own crontab.
      so, you can shutdown automagically one machine or several at your own desire.

  11. two cents.

    for turning on at the appropriate hour. restart your machine and goto to the bios.

    normally you can find something in “power control” or something like that. Here you can write the time you want your machine on. and voila! (ok, ok, … close the menu, probably F10 to save the changes and let the machine restart)

    in my case, my machine starts 07:45, so, when I arrive at 08:00 my sistem is ready. And in some cases some work is done in scripts.

    For delay an instruction, like shutdown, you can do it in several ways.

    only with shutdown, (rtfm) or consult a few lines above this one.

    with at

    with cron

    in both cases, please read the manual, man.!! In fact, you can consult several blogs and web pages to do that. I recommend you, here you can find a brief tutorial and …. examples!

    Good luck.

  12. Hi, I poetsd a comment on Toni Anicic’s blog about cron.He’s been very kind and tried to help, but maybe you are the right person for this topic.We are experiencing strange behavior with cron-based.After the two comments in Toni’s blog, we re-queued the newsletter, launched cron via wget and are observing the mail server’s behaviour.Current batch size ($countOfSubscritions) is 20.Right after the cron run, the mail server received 105 e-mails for delivery.How’s it that 20 becomes 105 with a single cron run?

Leave a Comment