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
- Shutdown/reboot the system
- Email yourself files
- Send birthday remainders
Commands
- 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
OR
# 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.
References:
- man pages crond, crontab, at
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins

- My 10 UNIX Command Line Mistakes
- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
Facebook it - Tweet it - Print it -
We're here to help you make the most of sysadmin work. So, subscribe!


{ 28 comments… read them below or add one }
Thank you.
Good Explanation..
continue putting information like this…!!
Thanks. I just scheduled my first cron job.
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..)
0 20 * * * /sbin/shutdown -r now
Use Login as root user and type reboot to reboot box:
rebootI 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
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 http://somehwere.com/path/to/some.file && haltnote: 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 http://somehwere.com/path/to/some.file 2>/home/kai/wget.log && haltso 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.
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
@ 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.
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.
Thanks! I was having trouble wrapping my head around the crontab thing. This showed how to do it (and by extension, how it works).
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!
Jan
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
thanks
and who can i have document about centos , install dns and public mail dns
hiii
Thanx for you all :-)
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.
Or if you want to schedule a shutdown in the next 24 hours:
shutdown -h timee.g:
shutdown -h 06:45i was trying to shutdown the SUSE from command promt using poweroff and shutdown but both command was not working???
Thank’s……………. good tips verry help full to me.
Thanks it was very help full…. and smart job .
hi, how can one find the command name? like for shutdown ,it’s /sbin/shutdown ?
Hi,
Can anybody suggest , How to restart/reboot a Linux machine from another machine?
Thanks,
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.
good work , Thanks, very helpful to me.
How can I shutdown my ubuntu system at 10:53 am.Please write the briefly.
ThankQ.
How can I shutdown others system. Please give reply.
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 thegeeksutff.com, here you can find a brief tutorial and …. examples!
Good luck.
Is it possible to schedule a reboot to boot to live usb instead to take automated disk images?