atd<\/code> service.<\/p>\n\n\n\nScheduling tasks using at command<\/h3>\n\n\n\n
The at command ordinarily expects time as the argument.<\/p>\n\n\n\n
at TIME<\/code><\/pre>\n\n\n\nWhere TIME can be specified using keywords such as;<\/p>\n\n\n\n
\nnoon<\/code>, midnight<\/code> or teatime (4:00 PM)<\/code>,<\/li>\n\n\n\nnext week<\/code>, tomorrow<\/code>, teatime tomorrow<\/code>, next tuesday<\/code>,next Tue<\/code>, next Tuesday<\/code>, next month<\/code>.<\/li>\n<\/ul>\n\n\n\nWhen executed with no commands or scripts passed to it, at<\/code> commands runs interactively and expects you to enter the commands to execute from the prompt.<\/p>\n\n\n\nat 11 PM Dec 2\nat><\/code><\/pre>\n\n\n\nAt the prompt, enter the command to run. For example;<\/p>\n\n\n\n
at 11 PM Dec 2\nat> echo \"This is a test at Job > \/tmp\/test-at-job\"<\/code><\/pre>\n\n\n\nat 11 PM Dec 2\nat> df -hT<\/code><\/pre>\n\n\n\nWhen done typing commands, press Ctrl+D to terminate input. When you press Ctrl+D, you will see <EOT><\/code> at the command line.<\/p>\n\n\n\nat 11 PM Dec 2\nat> df -hT<\/code><\/pre>\n\n\n\nYou can as well pass the commands to execute to at command from command line by specifying the file with commands using the -f<\/code> option. For example, consider a file called mycommands.sh<\/code> with two shell scripts<\/p>\n\n\n\ncat mycommands.sh\n\/home\/me\/myscripts\/clean-tmp.sh\n\/home\/me\/myscripts\/backup.sh<\/code><\/pre>\n\n\n\nTo have at execute these commands next week the same day at midnight;<\/p>\n\n\n\n
at -f mycommands.sh midnight next week<\/code><\/pre>\n\n\n\nYou can as well use the standard input redirection symbol;<\/p>\n\n\n\n
at teatime next month < mycommands.sh<\/code><\/pre>\n\n\n\nYou can also pipe tasks\/commands to at<\/code> command. For example to create a notification using the notify-send<\/code> command, <\/p>\n\n\n\necho 'notify-send \"You need to refill the gas\"' -t 1000 | at 17:00<\/code><\/pre>\n\n\n\nThis will send you a notification at 5 PM to refill the gas.<\/p>\n\n\n\n
NOTE:<\/strong><\/p>\n\n\n\n\n- For all the
at<\/code> examples that follows below, you can either pass the the commands or scripts or tasks\/jobs to be executed to at command or you can interactively enter them.<\/li>\n<\/ul>\n\n\n\nTo run the job one week from today, same time as when the at job was scheduled;<\/p>\n\n\n\n
at next week<\/code><\/pre>\n\n\n\nTo run the job at 4 PM tomorrow<\/p>\n\n\n\n
at teatime tomorrow<\/code><\/pre>\n\n\n\nRun a job on next Tuesday, same time as when the job was scheduled.<\/p>\n\n\n\n
at next tue<\/code><\/pre>\n\n\n\nRun the job next month, same date at midnight.<\/p>\n\n\n\n
at midnight next month<\/code><\/pre>\n\n\n\n\n- using the keyword
now<\/code> plus a time period. For example, if to schedule a task to run 4 hours from now, use the time period now + 4 hours<\/code>.<\/li>\n\n\n\n- For example;
To run the job today at 4PM plus 2 hours, that is at 6PM<\/li>\n<\/ul>\n\n\n\nat 4PM + 2 hours<\/code><\/pre>\n\n\n\nTo run the job one and half hour from now;<\/p>\n\n\n\n
at now + 90 minutes<\/code><\/pre>\n\n\n\nTo run the job two minutes from now;<\/p>\n\n\n\n
at now + 2 minutes<\/code><\/pre>\n\n\n\nTo run a job next on monday 2 hours after the same time when the job was scheduled;<\/p>\n\n\n\n
at monday + 2 hours<\/code><\/pre>\n\n\n\n\n- using a time of the day either in
24-hour<\/code> or 12-hour<\/code> clock system. For example; 16:00<\/code> or 4:00 PM<\/code>.<\/li>\n\n\n\n- For example;
To run the job at 5PM today;<\/li>\n<\/ul>\n\n\n\nat 5:00 PM or at 5 PM or at 17:00<\/code><\/pre>\n\n\n\n\n- using\u00a0
time of the day<\/code>\u00a0and\u00a0date<\/code>.\n\n- The date can be specified in the format
DD.MM.YY<\/code>, MMDDYY<\/code> or MM\/DD\/YY<\/code>.<\/li>\n\n\n\nMONTH Date, Year<\/code> or MONTH Date Year<\/code> or MONTH Date<\/code>. You can write the first three letters of the month e.g Jan<\/code> or jan<\/code>.<\/li>\n\n\n\n- For example,
To run the job on first october, year 2019 same time as when the job was scheduled<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\nat 12:30 PM 10\/01\/19 or at 12:30 PM 01.10.19 or at 12:30 PM 100119<\/code><\/pre>\n\n\n\nTo run the job on 2nd Jan, 2020 same time as when the job was scheduled<\/p>\n\n\n\n
at Jan 1, 2020 ot at Jan 1 2020<\/code><\/pre>\n\n\n\nTo run the job at 11 PM on 2nd Dec, this year;<\/p>\n\n\n\n
at 11 PM Dec 2<\/code><\/pre>\n\n\n\nList scheduled at jobs<\/h3>\n\n\n\n
At command has a utility called atq<\/code> that can be used to list at jobs that are pending execution.
To simply list the at jobs, run;<\/p>\n\n\n\natq<\/code><\/pre>\n\n\n\nIf there are any jobs pending execution, you will see them on the output;<\/p>\n\n\n\n
atq<\/code><\/pre>\n\n\n\n31 Mon Dec 2 23:00:00 2019 a root\n33 Sun Oct 6 16:00:00 2019 a root\n32 Fri Sep 13 00:00:00 2019 a root\n<\/code><\/pre>\n\n\n\nSimilarly, you can use at command with -l<\/code> option.<\/p>\n\n\n\nat -l<\/code><\/pre>\n\n\n\nDelete Scheduled at jobs<\/h3>\n\n\n\n
Scheduled at jobs can be removed using the atrm<\/code> utility or by passing option -r<\/code> to at command.<\/p>\n\n\n\natr -r <JOB ID><\/code><\/pre>\n\n\n\nor<\/p>\n\n\n\n
atrm <JOB ID><\/code><\/pre>\n\n\n\nFor example, based on the output of the atq<\/code> command above, you can remove at job with job number 31 using the command;<\/p>\n\n\n\nat -r 31<\/code><\/pre>\n\n\n\nor<\/p>\n\n\n\n
atrm 31<\/code><\/pre>\n\n\n\nTo remove all the jobs in the queue, simply obtain the job numbers and remove them as follows;<\/p>\n\n\n\n
atrm $(atq | cut -f1)<\/code><\/pre>\n\n\n\nThere are other options that are aliased to atrm<\/code> command.<\/p>\n\n\n\nat -d <JOB ID><\/code><\/pre>\n\n\n\nPrint Listed At Jobs to STDOUT<\/h3>\n\n\n\n
To print listed at jobs to standard output, simply use the command;<\/p>\n\n\n\n
at -c <JOB ID><\/code><\/pre>\n\n\n\nFor example, to cat the at job number 23 to standard output.<\/p>\n\n\n\n
at -c 23<\/code><\/pre>\n\n\n\nControlling Access to At<\/h3>\n\n\n\n
It is also possible to control who can run at jobs using the \/etc\/at.allow<\/code> and \/etc\/at.deny<\/code> files.<\/p>\n\n\n\n\n- only users listed in the
at.allow<\/code> file are allowed to use at<\/code><\/li>\n\n\n\n- users listed in
at.deny<\/code> file are not allowed to use at<\/code>.<\/li>\n<\/ul>\n\n\n\nUsing batch command<\/h3>\n\n\n\n
Another command almost similar to at command is batch<\/code> command. This command is used to schedule tasks that can only be executed when system load drops below 1.5 or any value specified in
Batch command does not accepts any parameters and runs interactively.<\/p>\n\n\n\nbatch\nat><\/code><\/pre>\n\n\n\nFor example to execute the script, \/home\/me\/myscripts\/clean-tmp.sh<\/code>, simply run batch<\/code> command and enter the script at the at<\/code> prompt.
Press Ctrl+d once you are done typing commands;<\/p>\n\n\n\nbatch\nat> \/home\/me\/myscripts\/clean-tmp.sh\nat> <\/eot><\/code><\/pre>\n\n\n\nbatch<\/code> command is no longer maintained on most Linux\/Unix distributions.<\/p>\n\n\n\nRead more about\u00a0at<\/code>\u00a0command on\u00a0man at<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"Our previous two guides, whose links are below, we covered how to schedule system tasks or jobs in Linux using the cron and anacron commands.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,1113,1110],"tags":[1116,1117,1118],"class_list":["post-4138","post","type-post","status-publish","format-standard","hentry","category-howtos","category-at-batch","category-automate-system-tasks","tag-at","tag-at-jobs","tag-batch","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4138"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=4138"}],"version-history":[{"count":2,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4138\/revisions"}],"predecessor-version":[{"id":21203,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4138\/revisions\/21203"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=4138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=4138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=4138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}