Marc Rasmussen
Marc Rasmussen

Reputation: 20555

My cron jobs runs several times

On my server i have three cron jobs:

by typing crontab -e i get the following:

0 */24 * * * wget -qO /dev/null http://www.example.com/Users/mailNotify?token=1234 >> /var/log/cronLog.txt
0 */23 * * * sh /var/www/backup/backupScript
0 */23 * * * wget -qO /dev/null http://www.example.com/Users/off_score?token=1234 >> /var/log/cronLog.txt

These cronjobs runs twice:

at 00.00 and at 01.00 every night.

The funny thing about this is that it runs all three jobs at each of the above hour.

Can anyone tell me what i have done wrong when creating these?

Upvotes: 0

Views: 186

Answers (1)

baao
baao

Reputation: 73241

To have your cronjobs running once at a specific time, you shouldn't use */ as this will make your cronjobs run every 23 hours, which causes the behaviour of running at 1 and then again, 23 hours later, at 0, as cron is calculating when to run to run every 23 hours during one day.

To run all of them at midnight like you commented, use cron like this:

0 0 * * * wget -qO /dev/null http://www.example.com/Users/mailNotify?token=1234 >> /var/log/cronLog.txt
0 0 * * * sh /var/www/backup/backupScript
0 0 * * * wget -qO /dev/null http://www.example.com/Users/off_score?token=1234 >> /var/log/cronLog.txt

Cron definitions:

# * * * * *  command to execute
 # │ │ │ │ │
 # │ │ │ │ │
 # │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 # │ │ │ └────────── month (1 - 12)
 # │ │ └─────────────── day of month (1 - 31)
 # │ └──────────────────── hour (0 - 23)
 # └───────────────────────── min (0 - 59)

You are telling cron to run every day with the 3rd * in the command.

Upvotes: 1

Related Questions