cron running tasks twice simultaneously! |
derekhed 05-19-2005, 12:06 PM I bought a new drive and set up a RAID on my G4 running OS 10.3.9. I have noticed that when the periodic daily task runs at night, it apparently is called twice and tries to run both processes simultaneously, which causes all kinds of problems since while one daily task is trying to move and compress files, the other task is already doing it and has a lock on the files, etc.
So I looked to see what crontabs were loaded:
Gandalf:~ root# ls -l /var/cron/tabs/
total 8
-rw------- 1 root wheel 1093 16 May 09:06 root
I then tried to make sure the default in /etc/crontab wasn't running in addition to this one by disabling it:
Gandalf:~ root# ls -l /etc/crontab
---------- 1 root wheel 296 2 May 11:22 /etc/crontab
This did not keep the problem from coming back, as last night my daily log shows everything repeated twice. This is the content of the lone crontab found in the /var/cron/tabs/ directory:
Gandalf:~ root# cd /var/cron/tabs/
Gandalf:/var/cron/tabs root# more root
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/Users/derekhed/bin/rootcrontab installed on Mon May 16 09:06:18 2005)
# (Cron version -- $FreeBSD: src/usr.sbin/cron/crontab/crontab.c,v 1.17 2001/06/16 03:16:52 peter Exp $)
# /etc/crontab
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
HOME=/var/log
#
#minute hour mday month wday who command
#
#*/5 * * * * /usr/libexec/atrun
#
# Run daily/weekly/monthly jobs.
15 3 * * * periodic daily
30 4 * * 6 periodic weekly
30 5 1 * * periodic monthly
3 0 * * * /Users/derekhed/bin/httpd.logrotate > /dev/null 2>&1
9 0 * * * /usr/local/bin/webalizer -Q
57 23 * * 6 /Users/derekhed/bin/BU_MySQL.sh -p *censored!* /Volumes/Ren/backups/db/entire_db.sql
27 * * * * /Users/derekhed/bin/FetchCache 0 > /Library/StartupItems/SETIatHome/bin/cache/Fetch0.out 2>&1
47 * * * * /Users/derekhed/bin/FetchCache 1 > /Library/StartupItems/SETIatHome/bin/cache/Fetch1.out 2>&1
36 1 * * * /Users/derekhed/bin/create_dmg.sh
*/5 * * * * /Users/derekhed/bin/prog > /Library/WebServer/Documents/prog.out
Note that there is only ONE call to periodic daily here. Why would it try and run it twice? Can anyone think of where I should look next? Any feedback is appreciated, thanks!
hayne 05-19-2005, 12:32 PM I don't have a Panther system handy to check, but as I recall, the periodic maintenance tasks were run via /etc/crontab
I don't know why you would have them in root's crontab - as I recall there was nothing in root's crontab on my Panther system.
I don't think you have disabled the standard /etc/crontab tasks just by making that file not readable - I think the tasks are loaded into memory. The /etc/crontab file is consulted only if it changes.
I would recommend removing the periodic tasks from root's crontab and reverting the permissions on the /etc/crontab file.
derekhed 05-19-2005, 12:59 PM Ok, I have reset the /etc/crontab file permissions as 444 (what they were originally, and issued this command as root:
Gandalf:/etc root# crontab -r
remove crontab for root? y
Now it would appear that I have NO crontab loaded for anyone... :confused:
Gandalf:/etc root# ls -l /var/cron/tabs/
Gandalf:/etc root#
I guess I will have to wait until tomorrow to see if I am really right here or if my 'phantom' crontab will fire.
No tabs appear in /var/cron/tabs/ anymore.
The reason I was mucking around with the /etc/crontab file was this bit out of the man pages:
Cron searches /var/cron/tabs for crontab files which are named after
accounts in /etc/passwd; crontabs found are loaded into memory. Cron
also searches for /etc/crontab which is in a different format (see
crontab(5)).
...
Additionally, cron checks each minute to see if its spool directory's
modtime (or the modtime on /etc/crontab) has changed, and if it has, cron
will then examine the modtime on all crontabs and reload those which have
changed.
hayne 05-19-2005, 01:22 PM Ok, I have reset the /etc/crontab file permissions as 444 (what they were originally, and issued this command as root:
Gandalf:/etc root# crontab -r
remove crontab for root? y
Now it would appear that I have NO crontab loaded for anyone
1) The permissions on my /etc/crontab in Tiger are 644. I don't recall what they were in Panther but 644 makes sense so that it is editable by root. (Ownership is root:wheel)
2) I'm not sure why you are surprised that you have no crontabs for any user. You used to have one for 'root' but you issued a command to remove it.
The "system" crontab (/etc/crontab) is always there. It is independent of the per-user crontabs that the command 'crontab' controls.
Yes - it is confusing.
derekhed 05-19-2005, 01:47 PM Thanks for your input hayne.
1. I copied the permissions from my laptop (also running jag)
2. Um, yeah!
My confusion stems from the fact that I have the same setup on my prior boot system (which I still keep around), and that never duplicated cron jobs. If I had only the root crontab, why would cron run the periodic tasks twice? :confused:
The way I figure it, one of two things must be happening:
1. There are two files called by the periodic script that do the same thing. This seems unlikely as they should run serially, right?
2. There are two crontab entries that both call periodic at the same time.
Now, it looks as if we addressed the second possibility by removing ALL crontabs. Now I predict that no maintenance tasks will run. About the first possibility, I don't know yet.
hayne 05-19-2005, 02:01 PM Now I predict that no maintenance tasks will run.
Don't you have the periodic maintenance tasks listed in /etc/crontab ?
(That is where they are on a default Panther installation.)
If so they should run.
nkuvu 05-19-2005, 03:05 PM I'm running Panther:
Aliens:~ nkuvu$ sudo crontab -u root -l
crontab: no crontab for root
Aliens:~ nkuvu$ ls -l /etc/crontab
-r--r--r-- 1 root wheel 296 12 Sep 2003 /etc/crontab
Aliens:~ nkuvu$ sudo ls -l /var/cron/tabs
total 4
-rw------- 1 root wheel 842 7 May 09:10 nkuvu
Note that I do have cron jobs running for my user account, and those aren't the daily tasks run by /etc/crontab.
derekhed 05-19-2005, 04:01 PM Ok, I found what I was doing wrong. I was using the /etc/crontab file as a template for my own crontabs. I then decided that I needed to run some things as root, and created a 'root' crontab in addition to the /etc/crontab file. I didn't realize that it was still run, and I had the periodic tasks in the new 'root' file I copied as well in the /etc/crontab.
Like I said... :o
hayne 05-19-2005, 10:19 PM I was using the /etc/crontab file as a template for my own crontabs.
Unfortunately, the per-user crontabs have a slightly different format than the system crontab - but I guess you noticed that.
derekhed 05-20-2005, 11:17 AM Thanks for the help. I got my system back running like it was supposed to, and I'll have to spend more time reading up on cron and crontab.
:)
|
|
|
|
|