11 Cron Scheduling Task Examples in Linux

If you have any questions or problems regarding this article and want help within 24 Hours? Ask Now

Ravi Saive

Simple Word a Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

You may also like...

17 Responses

  1. Hi Ravi, @daily is mentioned twice (repeated) under point no. 9(Special Strings for Common Schedule) . Good tut.

  2. Chad says:

    I know this was covered once, but && and || don’t mean exactly what is written above. && and || act like If..then logic where && is “then” and || is “else.” So in the cases mentioned in comments and in the article, you won’t get what you expect…. cmd1 && cmd2, will execute cmd1 and if it exits correctly (no errors) then cmd2 will be executed. In the case of cmd1 || cmd2, it’s the opposite, if cmd1 exits with something OTHER than exit 0 (there WERE errors,) then it will execute cmd2. SO! You COULD do something like, cmd1 && || which will work exactly like an if..then…else logic block.

    If you DO want to run multiple commands, you can do it two ways. Way the first, you could write a script and then have cron execute that script. I find that to be the best way cause then I get to add all sorts of logic and error handling that can’t be done on a single line in cron. If you don’t need to be fancy, the other way to go about it is:

    @daily /path/to/cmd1 ; /path/to/cmd2 ; /path/to/cmd3; etc….

    Keep in mind that this is true on the command line itself as well. You can:

    $ cmd1 ; cmd2

    OR

    $ cmd1 && cmd2 || cmd3

  3. Sal says:

    Thanks for the article. a useful tool crontab syntax generator like http://www.crontab-generator.org/ can help you write crontab line correctly.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Join Over 75000+ Linux Users
  1. 51334
  2. 2657
  3. 16705

Enter your email to get latest Linux Howto's