Jump to content

[SOLVED] Cron Job


jaymc

Recommended Posts

For some reason, cron jobs appear to be running multiple times

 

I have one in there which is

 

wget http://site.com (example)

 

Sometimes I can see that running 5 times via process list

 

It also used to do it with a mysqldump I had, which would crash mysql as it was being run 5 times consequatively

 

Any ideas what may be causing that?

Link to comment
Share on other sites

Cronjob syntax is as follows:

 

minute

hour

day-of-month

month-of-year

day-of-week

 

So a task that runs every minute would be as follows:

 

* * * * * task

 

A task that runs every seven minutes would be as follows:

 

*/7 * * * * task

 

The way you've got it set up, the first one will technically run every minute, although the /1 is unnecessary. However, the second one will only run at 07:00 each day.

 

This is all assuming that your cron manager follows the POSIX cron standards.

Link to comment
Share on other sites

Ok, I was right about cron running multiple times

 

I have just come on today to find my server almost dead after it had run and was still running my backup.sh script

 

This involves large copies and gzips aswell as DB locks

 

I seen 3 instances of it in process list, aswell as 120 wgets which run every minute and only takes 1 second

 

Hope some one knows what could cause cron to do this?

Link to comment
Share on other sites

Logs

 

Jan 22 06:12:01 hostname crond[17863]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:13:01 hostname crond[17891]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:14:01 hostname crond[17916]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:15:01 hostname crond[17964]: (root) CMD (/usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --con$
Jan 22 06:15:01 hostname crond[17968]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:16:04 hostname crond[18003]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:16:04 hostname crond[18004]: (root) CMD (wget -q http://hostname.co.uk/dbqueries/index.php)
Jan 22 06:17:02 hostname crond[18041]: (root) CMD (wget -q http://hostname.co.uk/dbqueries/cleanchatusers.php)
Jan 22 06:17:02 hostname crond[18042]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:18:04 hostname crond[18074]: (root) CMD (php -f /home/sitename/includes/cache/dynamic/homepage.php)
Jan 22 06:18:04 hostname crond[18075]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:18:04 hostname crond[18076]: (root) CMD (wget -q http://hostname.co.uk/dbqueries/cleanchatusers.php)
Jan 22 06:19:01 hostname crond[18114]: (root) CMD (wget -q http://hostname.co.uk/dbqueries/cleanchatusers.php)
Jan 22 06:19:01 hostname crond[18115]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:20:01 hostname crond[18146]: (root) CMD (/usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --con$
Jan 22 06:20:01 hostname crond[18149]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:21:03 hostname crond[18181]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:22:01 hostname crond[18207]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:23:04 hostname crond[18237]: (root) CMD (cd /home/backups && ./backup.sh)
Jan 22 06:24:02 hostname crond[18269]: (root) CMD (cd /home/backups && ./backup.sh)

 

backup.sh should be run once via this command in crontab

 

* 6 * * * cd /home/backups && ./backup.sh

 

Any idea what this is also? its not in crontab (crontab -e)

 

Jan 22 06:20:01 hostname crond[18146]: (root) CMD (/usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --con$

 

Hope someone can help..

Link to comment
Share on other sites

Here is my cron conf

 

  GNU nano 1.2.4                    File: crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

Link to comment
Share on other sites

backup.sh should be run once via this command in crontab

 

* 6 * * * cd /home/backups && ./backup.sh

 

 

I'm not sure what you're trying to accomplish with this, but as it stands, it's going to run that job every minute in the 06 hour. So it'll run it at 06:00, 06:01, 06:02, and so on. The same thing will happen with your * 7 * * *. You need to change them to 0 6 * * * and 0 7 * * *, respectively.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.