How to Use ‘at’ Command to Schedule a Task on Given or Later Time in Linux

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

4 Responses

  1. Jalal Hajigholamali says:

    Hi,
    Very useful article

    remove extra ‘d ‘ from atdd

    # chkconfig –level 35 atdd on

  2. Marcelo says:

    Very useful, thank you!

  3. Sergey Podushkin says:

    Good article, Gabriel!

    Just my 5 cents to it.

    “at” can be used to start something on background, like nohup staff, but more short:
    $ echo “rsync remote_resource local_resource” | at now
    or
    $ at -f /path/to/my/script -m now
    just notice “-f script” option – it’s very convenient to run more complex staff

    “at” can be used instead of cron to run something repeatedly after the first execution ends. This can eliminate cronjobs, scheduled to run each minute with various locks to avoid to run several commands simultaneously. One can add at the end of its script:
    —— bash code snippet —–
    # script payload here
    this_script_name=$(basename $0)
    this_script_path=$(readlink –canonicalize $(dirname $0))
    at -f $this_script_path/$this_script_name now
    —— bash code snippet —–
    this will start the script again when it’s finished.

    Another interesting application that’s unable to implement with cron is periodically execution with random intervals. Mostly the same as abouve, but just add random delay:
    —— bash code snippet —–
    # script payload here
    this_script_name=$(basename $0)
    this_script_path=$(readlink –canonicalize $(dirname $0))
    MIN_DELAY=15
    RANDOM_BIAS=20
    delay=$(( ($RANDOM % $RANDOM_BIAS) + $MIN_DELAY ))
    at -f $this_script_path/$this_script_name now + $delay min
    —— bash code snippet —–

    That’s all :)

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

Join Over 300K+ Linux Users
  1. 177,942
  2. 8,310
  3. 37,548

Are you subscribed?