CentOS 8.x Basics of at for running command at specific time

From Notes_Wiki

Home > CentOS > CentOS 8.x > System Administration > atd or at > Basics of at for running command at specific time

We can use at, atq, atd etc. to run a specified job at a given time. There is also command batch which allows executing command when system load average is low (Default <0.8). This is different then cron which is used to run commands repeatedly after desired interval.


Ensure that atd is running

atd daemon or service is used to run jobs at specified time. To validate that it is running use:

systemctl status atd


Submit job to be executed at given time

We can submit job to be executed at given time using 'at' using following syntax

at -t <time>
#After this type the commands one at a time on "at>" prompt
#Use Ctrl+D to stop typing and complete submitting jobs

By default it goes to queue named 'a'. Here format of time is [[CC]YY]MMDDhhmm[.ss]


For example

[root@backup rsnapshot_backups]# at -t 11040840 
at> /usr/bin/rsnapshot du
at> <EOT>
job 2 at Wed Nov  4 08:40:00 2020
[root@backup rsnapshot_backups]#

Here, giving full path /usr/bin/rsnapshot is not required. As such at will take current environment and use it while running the specified job.


There is more advanced option of using 'at -q <queue> timespec' where timespec can be

  • 4pm + 3 days
  • now + count time-units, where time-units can be minutes, hours, days, or weeks
  • 1am tomorrow


The output of the job is emailed to user. So if /etc/aliases is set correctly and outgoing emails are working (postfix configure properly), then the output would be received via email. Other option is to redirect output to a file.


See the job queues

We can see the job queues and when they will be executing using:

atq


See job details

As such job details are not visible using at commands. But we can go to folder '/var/spool/queue' and search for job file with name '<queue-letter>000<job-no>'. For example to list job 2 of queue a we can use:

cat /var/spool/at/a00002019808fe

For Determining hexadecimal string '019808fe', first do 'ls /var/spool/at/' and then use the cat command.



Home > CentOS > CentOS 8.x > System Administration > atd or at > Basics of at for running command at specific time