Bootstrap FreeKB - Linux Commands - at (schedule a one time job)
Linux Commands - at (schedule a one time job)

Updated:   |  Linux Commands articles

The at command is used to schedule a job to run once, at a certain date and time.

 


Use apt-get or yum to install at.

[root@server1 ~]# yum install at

 


Creating an at job

The at command without any options will display Garbled time. The at command at least requires a date or time.

[root@server1 ~]# at
Garbled time

 

To schedule a job using at, issue the at command followed by the date and time to run the at job. In this example, a job is scheduled to run on January 1st 2016 at 5:00 PM, and the at job will execute the Example.sh file. When done creating the at job, press Ctrl + D to save the job.

[root@server1 ~]# at 17:00 2016-01-01
at> sh /home/user1/bin/Example.sh
at> <EOT>
job 1 at Wed Jan 01 17:00:00 2016

 

The at command can accept many different formats of the date and time.

[root@server1 ~]# at noon
[root@server1 ~]# at noon tomorrow
[root@server1 ~]# at midnight
[root@server1 ~]# at friday
[root@server1 ~]# at fri
[root@server1 ~]# at next fri
[root@server1 ~]# at 200
[root@server1 ~]# at 2:00
[root@server1 ~]# at 2:00 AM
[root@server1 ~]# at 2:00 PM
[root@server1 ~]# at 14:00
[root@server1 ~]# at 1400
[root@server1 ~]# at 1400 tomorrow

 


Running a script file

Redirection, or the -f option, can be used to run a script file once at a certain date and time.

[root@server1 ~]# at 18:00 2016-01-01 < /home/user1/bin/Example.sh
job 2 at Wed Jan 01 18:00:00 2016

 

[root@server1 ~]# at 17:00 2016-01-02 -f /home/user1/bin/Example.sh
job 1 at Thur Jan 02 17:00:00 2016

 


Send email

The at -m (send mail) can be used to send an email when the at job is executed.

[root@server1 ~]# at -m 17:00 2016-01-01 < /home/user1/bin/Example.sh
job 1 at Wed Jan 01 17:00:00 2016

 


Do not send email

The at -M (do not send email) can be used to ensure an email is not sent when the at job is executed.

[root@server1 ~]# at -M 17:00 2016-01-01 < /home/user1/bin/Example.sh
job 1 at Wed Jan 01 17:00:00 2016

 


Verbose

The at -v (verbose) option will print the date and time the job is scheduled to run.

[root@server1 ~]# at -v 17:00 2016-01-02 -f /path/to/script.sh
Thur Jan 02 17:00:00 2016
job 1 at Thur Jan 02 17:00:00 2016

 


Viewing pending at jobs

The atq or at -l (list) commands can be used to view the at jobs in queue.

[root@server1 ~]# atq
3    Mon Jan 01 01:00:00 2016 a root
2    Mon Jan 01 02:00:00 2016 a root
1    Mon Jan 01 05:00:00 2016 a root

[root@server1 ~]# at -l
3    Mon Jan 01 01:00:00 2016 a root
2    Mon Jan 01 02:00:00 2016 a root
1    Mon Jan 01 05:00:00 2016 a root

 


Removing at jobs

The at -r (remove), atrm , and at -d (delete) commands can be used to remove a job from the at queue.

[root@server1 ~]# at -r 3
[root@server1 ~]# at -d 3
[root@server1 ~]# atrm 3

[root@server1 ~]# atq
2    Mon Jan 01 02:00:00 2016 a root
1    Mon Jan 01 05:00:00 2016 a root

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e652b5 in the box below so that we can be sure you are a human.