How to Run or Repeat a Linux Command Every X Seconds Forever

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.

Marin Todorov

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

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

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Introduction to Linux - A Hands on Guide

You may also like...

7 Responses

  1. Kenton says:

    Instead of “while true; do (some command);sleep 3;done” You can just use “while sleep 3;do (some command);done”

    The sleep command returns true in a conditional.

  2. Michael says:

    Please how will i grep a string in a log file to output the lastest string in the file.

    Thanks for your answer as usual.

  3. Stef says:

    Another nice command is ‘at’ that executes the commands specified from the input stream at a given time. On Debian, it is provided by the package at.

    The nice thing about ‘at’ is that the time specification is quite flexible and intuitive
    echo notify-send Hoops | at now + 5 minute
    echo notify-send Hoops | at 10pm
    echo notify-send Hoops | at 10pm tomorrow
    echo notify-send Hoops | at 22:00 monday

    By itself t does not repeat but that can easily be done using a loop.

    for ((i=1;i<10;i++)) ; do echo echo notify-send "Hoops $i" | at now + $i minute ; done

    Be aware that 'at', like cron, executes its commands in a clean environment so without most environment variables such as DISPLAY.

  4. Shahid Khattak says:

    Nice article. especially to check free memory in real time and checking system average load

  5. Vicdeveloper says:

    Saved in Favorites. :D. Thanks

  6. John Thingstad says:

    How about a introduction to time dependent tasks in systemd?. cron is on the way out anyways.

Got something to say? Join the discussion.

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

Join Over 150K+ Linux Users
  1. 100,756
  2. 5,113
  3. 36,418

Enter your email to get latest Linux Howto's