Howto: Shutdown Linux Box Automatically

by on October 2, 2005 · 30 comments· LAST UPDATED January 9, 2010

in , ,

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
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 30 comments… read them below or add one }

1 arun August 17, 2007 at 6:52 am

Thank you.


2 Ganesh October 11, 2007 at 12:33 pm

Good Explanation..

continue putting information like this…!!


3 seren6ipity February 17, 2008 at 8:46 pm

Thanks. I just scheduled my first cron job.


4 kana March 31, 2008 at 12:55 pm

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


5 Ron April 19, 2011 at 7:00 pm

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


6 nixCraft March 31, 2008 at 1:00 pm

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


7 Rahul Hulawale April 3, 2008 at 11:01 am

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


8 kai May 14, 2008 at 5:51 pm

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.


9 saroj June 26, 2008 at 11:16 am

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


10 peachy September 20, 2008 at 4:55 pm

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


11 Anshul Shrivastava May 15, 2009 at 8:41 am

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.


12 Martijn June 12, 2009 at 7:28 pm

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


13 Jan van Leeuwen June 19, 2009 at 11:03 am

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!



14 mr tran July 9, 2009 at 3:31 am

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


15 Saleh Mansour July 23, 2009 at 11:07 am

Thanx for you all :-)


16 Sagar Mhatre August 21, 2009 at 6:06 pm

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.


17 Frederik Questier August 31, 2009 at 7:47 pm

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

shutdown -h time
shutdown -h 06:45


18 Harish November 30, 2009 at 12:11 pm

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


19 kamal December 17, 2009 at 6:09 pm

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


20 Aaqib February 8, 2010 at 7:44 pm

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


21 pranay August 17, 2010 at 12:55 am

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


22 Vishnu September 24, 2010 at 5:42 am

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



23 carlos December 6, 2010 at 11:53 pm

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.


24 a.gaurav June 17, 2011 at 5:44 am

good work , Thanks, very helpful to me.


25 Siva September 20, 2011 at 5:25 am

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


26 Syam September 20, 2011 at 5:28 am

How can I shutdown others system. Please give reply.


27 carlos September 21, 2011 at 9:45 pm

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.


28 Fersu December 12, 2011 at 11:34 pm

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


29 Daniel February 7, 2012 at 12:44 pm

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?


30 Rakesh July 19, 2012 at 7:10 am

its nice u can use crontab -e -u root


Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous post:

Next post: