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 wanna shutdown Linux box automatically everyday 8 pm then you need to use cron instead of at command (see below for example). Useful to schedule recurring events or daily events such as backup, check system security etc.
Let us come back to our example, shutting down Linux automatically at 8 pm, type command at 8pm and press enter key, then type halt followed by enter key. To save your job press CTRL+D.
# at 8pm
You can also try out 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 following command:
# /etc/init.d/atd start
Linux Cron job to Shutdown Linux server/Desktop system:
(1) Login as root user and at shell prompt type crontab -e command so that you can add cronjob
# crontab -e
# crontab -e -u root
(2) Append following entry to it (shutdown at 20:00 hrs [24 hrs format]):
0 20 * * * /sbin/shutdown -h now
(3) Save the changes and exit to shell prompt.