Batch & at both of these commands can be used for scheduling a one-time job. Depending on CPU load or specific time you can choose either of them. Lets, deep dive into these commands.
Batch commands for Scheduling
If you have to run scheduled job/s when the system is less busy, batch command is the best option for you. Batch read commands from standard input or a specified file which are to be executed when system load levels permit; in other words when the load average drops below _LOADAVG_MX (1.5), or the value specified in the invocation of atrun.
So, here is the load average of my pc, less than 1.5
Now, run batch with below commands.
Ctrl+d when done with batch commands. As the load is below 1.5, the commands will run immediately. Now check, with list (ls) command
So the batch command echo “batch test” > batch-test.txt ran perfectly, created a text file with a single line (batch test) in it.
Now, to check the second command cat batch-test.txt , check by opening /var/spool/mail/$USER file
Here is my output at the end.
Now, what if, the system load average is over 1.5 ? In this example, I am going to use batch, atq, w commands.
These are the commands that will after batch command.
mkdir -p ~/demo-batch-dir cd ~/demo-batch-dir/ echo "This is a demo line" > batch-demo.txt
Now carefully, watch this,
Here, we scheduled some commands to run after batch command. But the system load is higher (4.07) so the scheduled commands are not executed. We can see that they are in queue using atq command. Checked the load average of the system, which is just over 4.00, so we use atrun command as sudo and the scheduled batch commands runs immediately. Then we confirm that the scheduled commands ran properly by going into the newly created demo-batch-dir directory.
If you want to remove or delete the jobs that are scheduled, it can be done with atrm command. Below is an example of atrm command.

Using At to schedule Jobs
If you are planning to run schedule a job once but at a specific time and date, at command is the best option for you. At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a specific time of day. The at command can be anything from a simple reminder message to a complex script.
For example, to run a job at 4 pm three days from now, you would do at 4pm + 3 days, to run a job at 10:00am on July 31, you would do at 10 am Jul 31 and to run a job at 1 am tomorrow, you would do at 1 am tomorrow.
Basic syntax for at command
at now + 5 minutes
at > {following commands}
Here, I am telling commands to run 5 minutes from the current time. Below is an example of it,
Here, around system time 02:55, I schedule a job using at command with +5 minute, which will print the string – “testing at command”. Pressing Ctrl+d in a new line will place my job on the queue. We checked queue with atq command after that, it shows that the job will run at exactly 03:00.
At 03:00 hour we get this message in our terminal.
You have new mail in /var/spool/mail/sihamsharif
If you check the mail in /var/spool/mail/sihamsharif, you will see the message we scheduled is in the mail body.
The complete procedure is given below,
On the subject you can see the job ID no, in our case it is number 33.
The definition of the time specification can be found in /usr/share/doc/at-<VERSION>/timespec. At uses a very casual representation of time and date. Suppose our current system date time is 09:00 AM July 4th, 2021, now running at with below time expression (column 2) results in column 3.
time syntax |
time expression |
it will run on |
| TEATIME | TEATIME | 4:00 PM July 4 2021 |
| MIDNIGHT | MIDNIGHT | 12:00 AM July 4 2021 |
| NOON | NOON | 12:00 AM July 4 2021 |
| time_hour_min am_pm | 9:00 AM | 9:00 AM July 5 2021 |
| hr24clock_hr_min / HOURMIN | 1430 | 2:30 PM July 4 2021 |
| month_name | 9:00 PM Aug 4 | 9:00 PM August 4 2021 |
| day_of_week | 10:00 PM Thu | 10:00 PM July 8 2021 |
| increment in days | now + 2 days | 9:00 AM July 6 2021 |
| increment in hour | now + 12 hour | 9:00 PM July 4 2021 |
| increment in weeks | now + 2 weeks | 9:00 AM July 18 2021 |
All the time syntax can be found in timespec file under /usr/share/doc/at-<VERSION>/ directory. Running at command without time expression results in “Garbled time”. So whenever using at always put the proper time expression for the job.
If you find this article useful, you may want to read about Automating Task with Cron and Anacron. I covered some basics about Cron and Anacron job scheduler in that article.







