Howto: Shutdown Linux Box Automatically

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 30 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
30 comments… add one
  • arun Aug 17, 2007 @ 6:52

    Thank you.

  • Ganesh Oct 11, 2007 @ 12:33

    Good Explanation..

    continue putting information like this…!!

  • seren6ipity Feb 17, 2008 @ 20:46

    Thanks. I just scheduled my first cron job.

  • kana Mar 31, 2008 @ 12:55

    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..)

    • Ron Apr 19, 2011 @ 19:00

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

  • 🐧 nixCraft Mar 31, 2008 @ 13:00

    Use Login as root user and type reboot to reboot box:

  • Rahul Hulawale Apr 3, 2008 @ 11:01

    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

  • kai May 14, 2008 @ 17:51

    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.

  • saroj Jun 26, 2008 @ 11:16

    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

  • peachy Sep 20, 2008 @ 16:55

    @ 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.

  • Anshul Shrivastava May 15, 2009 @ 8:41

    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.

  • Martijn Jun 12, 2009 @ 19:28

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

  • Jan van Leeuwen Jun 19, 2009 @ 11:03

    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!


  • mr tran Jul 9, 2009 @ 3:31

    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

  • Saleh Mansour Jul 23, 2009 @ 11:07

    Thanx for you all 🙂

  • Sagar Mhatre Aug 21, 2009 @ 18:06

    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.

  • Frederik Questier Aug 31, 2009 @ 19:47

    Or if you want to schedule a shutdown in the next 24 hours:

    shutdown -h time
    shutdown -h 06:45

  • Harish Nov 30, 2009 @ 12:11

    i was trying to shutdown the SUSE from command promt using poweroff and shutdown but both command was not working???

  • kamal Dec 17, 2009 @ 18:09

    Thank’s……………. good tips verry help full to me.

  • Aaqib Feb 8, 2010 @ 19:44

    Thanks it was very help full…. and smart job .

  • pranay Aug 17, 2010 @ 0:55

    hi, how can one find the command name? like for shutdown ,it’s /sbin/shutdown ?

  • Vishnu Sep 24, 2010 @ 5:42

    Can anybody suggest , How to restart/reboot a Linux machine from another machine?


    • carlos Dec 6, 2010 @ 23:53

      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.

  • a.gaurav Jun 17, 2011 @ 5:44

    good work , Thanks, very helpful to me.

  • Siva Sep 20, 2011 @ 5:25

    How can I shutdown my ubuntu system at 10:53 am.Please write the briefly.

  • Syam Sep 20, 2011 @ 5:28

    How can I shutdown others system. Please give reply.

  • carlos Sep 21, 2011 @ 21:45

    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.

  • Fersu Dec 12, 2011 @ 23:34

    Is it possible to schedule a reboot to boot to live usb instead to take automated disk images?

  • Daniel Feb 7, 2012 @ 12:44

    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?

  • Rakesh Jul 19, 2012 @ 7:10

    its nice u can use crontab -e -u root

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum