1. Technology
Send to a Friend via Email
Basic Linux Operations FAQ

Part 3 of the Linux Newbie Administrator Guide

3.3.2 How do I execute a command at specified time (using "at" or "batch")?
(continued after the ads...)

Related Resources
Linux Newbie Administrator Guide
0. Linux Benefit
1. Before Installation
2. Linux Resources/Help
3. Basic Operations FAQ
4. Newbie Admin FAQ
~ 4.1 Lilo
~ 4.2 Drives
~ 4.3 X-Windows
~ 4.4 Configurations
~ 4.5 Networking
5. Shortcuts / Commands
6. Linux Applications
7. Learn Linux Commands
A. How to Upgrade Kernel?

The at command will execute the command(s) you specify at the date and time of your choice. For example, I could start playing music from my CDROM at 7 o'clock in the morning:

at 7:00
cdplayd

In the example above, I entered the first line "at 7:00" on the command line and then pressed ENTER. To this, the at command displayed a prompt "at>". At this prompt, I entered my command "cdplay" and then pressed the control key and "d" simultaneously to finish the input. If instead of pressing d , I pressed "ENTER", the next "at>" prompt would appear, at which I would be able to enter the next command to be executed right after "cdplay", also at 7:00. And so on, I could have had many commands scheduled for execution one by one starting at 7:00. After typing the last command, I would finish the input with d. Think of the d as sending "end-of-file" to the current input. Don't press d twice because this will log you out--that's what d does when entered straight on the Linux command line.

You can list the job you scheduled for execution using:

at -l

which will give you the numbered list of the jobs waiting.

If you changed your mind, you can remove a job from this list. For example:

atrm 8

will remove the job with the number eight on the list.
I could also schedule a job for execution much later, for example:

at 23:55 12/31/00
startx

would start my X-windowing system right on time for the new millennium (5 minutes before midnight on 31 of December 2000).
If you cannot execute the at command, check if the at daemon ("atd") is loaded (as root, use ntsysv). If you cannot execute the at command as a regular user although it works for root, check if the empty file /etc/at.deny exists and there is no file /etc/at.allow. This should be the default setup and it permits all the users to execute at. If you want only certain users to use at, create a file /etc/at.allow and list these users there.
For other options, check:

man at

If you wish to perform a processor-intensive job in the background when the system load is low, you may choose to use the batch command. For example, I could run setiathome (a program crunching data to help in search of extraterrestrial intelligence, SETI) using:

batch
at>setiathomed

In this example, I entered the command batch and then, at the "at>" prompt, I entered the command which I wanted to be executed in the background. The job tries to start immediately, but goes ahead only when the system load is under 0.8 You can check the system load by inspecting the contents of the (virtual) file /proc/loadavg . For example:

cat /proc/loadavg

When a batch job finishes, the output is sent to me via e-mail.

Next > 3.3.3 How do I set up cron?

Can't find what you are looking for?
Search the

Stay up-to-date!
Subscribe to the Linux free newsletter.

You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

©2014 About.com. All rights reserved.