Schedule One Time Tasks Linux

Schedule One Time Tasks Linux

From time to time, you want to run a command or set of commands at a set point of the future. These scheduled commands usually called tasks or jobs. One of the solutions is to use at. This is not a standalone tool, but rather a system daemon atd. atd can be found in the at package.

Scheduling Jobs

Create a new job (to finish the input use CTRL+D):

at 

To show the at queue.lists the user’s pending jobs, unless the user is the superuser; in that case, everybody’s jobs are listed. The format of the output lines (one for each job) is: Job number, date, hour, queue, and username.

[root@knesenko-centos7 ~]# atq
4	Fri Jul 24 09:42:00 2015 a root

Show the job content:

 at -c #job number

Remove the job:

atrm #job number

Time formats:

noon
midnight
teatime
tomorrow
noon tomorrow
next week
next monday
fri
NOV
9:00 AM
1:45 PM
1430
1:45 PM tomorrow
1:45 PM next month
1:45 PM 10/21
1:45 PM Oct 21
1:45 PM October 21 2014
1:45 PM 10/21/2014
1:45 PM October 21 2014
1:45 PM 21.10.14
1:45 PM October 21 2014
now + 30 minutes
now + 1 hour
now + 2 days

So for example you can run:

at now + 30 minutes
at> echo ok
at> 
job 4 at Fri Jul 24 09:42:00 2015

Securing at daemon
There two files you need to know. /etc/at.allow and /etc/at.deny. Using the first one will let you use whitelist. Second one is blacklist. I recommend using whitelist with /etc/at.allow. Each line write down the username that is allowed to create at jobs.

Batch
batch executes commands when system load levels permit; in other words, when the load average drops below 0.8, or the value specified in the invocation of atd.