Running a cron job 3 times (1 pm, 2 pm and 3 pm for example)?

I am not sure how to run a cron job at 3 specific hours every day. I want to run it at 1pm, 2 pm and 3pm.

Is it possible, using a single expression?

96944 次浏览

you may use this:

# m   h   dom mon dow   command
0 13,14,15 *   *   *     /home/user/command

your /home/user/command will be run at 13:00, 14:00 and 15:00

As lenik stated, it can be done in single expression.

0 13,14,15 * * * <your-script-to-run>

Check this geedkstuff link for more examples

You can try the following as well:

0 13-15 * * * /home/apps/sample.sh

While the given answers are correct, an unexperienced user might not know where to put this expression. You have to edit the crontab file, like:

crontab -e

There you add

0 13,14,15 *   *   *     /home/user/command

to execute your command at 13:00, 14:00 and 15:00. Also note that user has to be substituted with the user account the command is executed in.

To anyone landing here --> useful tool:

https://crontab.guru/

Please prefer range+step over commas:

Example: Run every 2h from 9h to 16h
m    h     dom mon dow   command
0  9-16/2   *   *   *     /home/user/command

Also applicable to minutes:

    m        h     dom mon dow   command
10-30/10  9-16/2   *   *   *     /home/user/command

Crontab guru shows what it means, and the next scheduled jobs.

For example I typed this cron at 10h05:

enter image description here