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

From Notes_Wiki
Revision as of 03:18, 4 November 2020 by Saurabh (talk | contribs) (Created page with "<yambe:breadcrumb self="Basics of at for running command at specific time">CentOS 8.x atd or at|8.x atd or at</yambe:breadcrumb> =CentOS 8.x Basics of at for running command a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<yambe:breadcrumb self="Basics of at for running command at specific time">CentOS 8.x atd or at|8.x atd or at</yambe:breadcrumb>

CentOS 8.x 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


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.



<yambe:breadcrumb self="Basics of at for running command at specific time">CentOS 8.x atd or at|8.x atd or at</yambe:breadcrumb>