{"id":13209,"date":"2019-04-01T07:53:57","date_gmt":"2019-04-01T07:53:57","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13209"},"modified":"2019-04-01T07:53:57","modified_gmt":"2019-04-01T07:53:57","slug":"how-to-use-at-command-to-schedule-a-task-on-given-or-later-time-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-use-at-command-to-schedule-a-task-on-given-or-later-time-in-linux\/","title":{"rendered":"How to Use \u2018at\u2019 Command to Schedule a Task on Given or Later Time in Linux"},"content":{"rendered":"<p>As an alternative to\u00a0<a href=\"https:\/\/www.tecmint.com\/11-cron-scheduling-task-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cron job scheduler<\/a>, the\u00a0<code>at<\/code>\u00a0command allows you to schedule a command to run once at a given time without editing a configuration file.<\/p>\n<p>The only requirement consists of installing this utility and starting and enabling its execution:<\/p>\n<pre># yum install at              [on CentOS based systems]\r\n$ sudo apt-get install at     [on Debian and derivatives]\r\n<\/pre>\n<p>Next, start and enable the at service at the boot time.<\/p>\n<pre>--------- <strong>On SystemD<\/strong> ---------\r\n# systemctl start atd\r\n# systemctl enable atd\r\n\r\n--------- <strong>On SysVinit<\/strong> ---------\r\n# service atd start\r\n# chkconfig --level 35 atd on\r\n<\/pre>\n<p>Once\u00a0<code>atd<\/code>\u00a0is running, you can schedule any command or task as follows. We want to send\u00a0<strong>4<\/strong>\u00a0ping probes to\u00a0<code>www.google.com<\/code>\u00a0when the next minute starts (i.e. if it\u2019s\u00a0<strong>22:20:13<\/strong>, the command will be executed at\u00a0<strong>22:21:00<\/strong>) and report the result through an email (<code>-m<\/code>, requires\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-postfix-mail-server-and-dovecot-with-mariadb-in-centos\/\" target=\"_blank\" rel=\"noopener\">Postfix<\/a>\u00a0or equivalent) to the user invoking the command:<\/p>\n<pre># echo \"ping -c 4 www.google.com\" | at -m now + 1 minute\r\n<\/pre>\n<p>If you choose to not use the\u00a0<code>-m<\/code>\u00a0option, the command will be executed but nothing will be printed to standard output. You can, however, choose to redirect the output to a file instead.<\/p>\n<p>In addition, please note that\u00a0<code>at<\/code>\u00a0not only allows the following fixed times: now, noon (12:00), and midnight (00:00), but also custom 2-digit (representing hours) and 4-digit times (hours and minutes).<\/p>\n<p>For example,<\/p>\n<p>To run\u00a0<code>updatedb<\/code>\u00a0at\u00a0<strong>11 pm<\/strong>\u00a0today (or tomorrow if the current date is greater than\u00a0<strong>11 pm<\/strong>), do:<\/p>\n<pre># echo \"updatedb\" | at -m 23\r\n<\/pre>\n<p>To shutdown the system at\u00a0<strong>23:55<\/strong>\u00a0today (same criteria as in the previous example applies):<\/p>\n<pre># echo \"shutdown -h now\" | at -m 23:55\r\n<\/pre>\n<p>You can also delay the execution by minutes, hours, days, weeks, months, or years using the\u00a0<code>+<\/code>\u00a0sign and the desired time specification as in the first example.<\/p>\n<p>Time specifications are subject to the\u00a0<a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\/utilities\/at.html\" target=\"_blank\" rel=\"nofollow noopener\">POSIX standard<\/a>.<\/p>\n<h3>Summary<\/h3>\n<p>As a rule of thumb, use at instead of\u00a0<a href=\"https:\/\/www.tecmint.com\/11-cron-scheduling-task-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cron job scheduler<\/a>\u00a0whenever you want to run a command or execute a given task at a well-defined time only once. For other scenarios, use\u00a0<strong>cron<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-cron-alternative-at-command-to-schedule-tasks\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As an alternative to\u00a0cron job scheduler, the\u00a0at\u00a0command allows you to schedule a command to run once at a given time without editing a configuration file. The only requirement consists of installing this utility and starting and enabling its execution: # yum install at [on CentOS based systems] $ sudo apt-get install at [on Debian and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-use-at-command-to-schedule-a-task-on-given-or-later-time-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Use \u2018at\u2019 Command to Schedule a Task on Given or Later Time in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13209","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13209"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13209\/revisions"}],"predecessor-version":[{"id":13210,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13209\/revisions\/13210"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}