Post #318,458
12/11/09 5:07:34 PM
12/11/09 5:17:42 PM
|
Odd cron/links behavior
I've got a PHP script that I copied over from another server. It worked fine there, calling it via 'lynx -dump' from crontab.
The new system didn't have lynx, so I used links instead.
Now I'm getting duplicate execution. I capture the output from the cronjob to a txt file, and that's only showing one instance. But the log file that I write line-by-line within the script shows about 4-7 seconds after the scirpt starts, it starts again.
My suspicion is that the "-dump" option on links is causing it to re-execute so it can grab the output, the way way Firefox often re-executes a page when you try to view source.
Has anyone heard of this problem, or have any other ideas where I should look?
[edit]
links vs. lynx was a red herring. I remembered I had sudo on the box and installed lynx, and that's doing the same thing. This only happens when called via cron, calling the script manually works fine.
--
Drew
Edited by drook
Dec. 11, 2009, 05:17:42 PM EST
|
Post #318,459
12/11/09 6:04:46 PM
|
I usually use wget for stuff like that.
Regards, -scott Welcome to Rivendell, Mr. Anderson.
|
Post #318,461
12/11/09 7:24:49 PM
|
How?
I just looked at the man page and didn't see an option to dump output to stdout. Or do you let it keep dropping numbered files, rather than have it write to a logfile?
--
Drew
|
Post #318,462
12/11/09 7:57:33 PM
|
cmd >>out.txt file appends output to out.txt
or cmd >outputfile 2>&1
to catch any errors as well
thanx,
bill
|
Post #318,465
12/11/09 9:52:33 PM
|
Re: How?
-O file
--output-document=file
The documents will not be written to the appropriate files,
but all will be concatenated together and written to file.
If - is used as file, documents will be printed to standard
output, disabling link conversion. (Use ./- to print to a
file literally named -.)
Regards, -scott Welcome to Rivendell, Mr. Anderson.
|
Post #318,466
12/11/09 10:20:35 PM
|
Ahh, output-document ... so intuitive
I'll give it a try, but it may not help. I've tried it now with links and lynx, and it does the same thing. Just added logging the pid and creating a lockfile. It's the same process, but for some reason when run via cron it executes the script twice. When I call it manually it just executes once.
Is there a system-level log of what cron executes? What I mean is, aside from the logging that I do myself within the script, is there a log that shows "cron executed script foo at time"?
--
Drew
|
Post #318,468
12/11/09 11:22:21 PM
|
typically /var/log/messages and any output is sent to root..
or the user the cron is executed as.
|
Post #318,481
12/12/09 12:31:03 PM
|
Nothing in /var/log/messages
But /var/log/auth.log shows cron starting and stopping. For some reason cron runs twice each minute for root.
auth.log:Dec 12 09:14:01 ps17185 CRON[22094]: (pam_unix) session opened for user root by (uid=0)
auth.log:Dec 12 09:14:01 ps17185 CRON[22094]: (pam_unix) session closed for user root
auth.log:Dec 12 09:15:01 ps17185 CRON[22788]: (pam_unix) session opened for user root by (uid=0)
auth.log:Dec 12 09:15:01 ps17185 CRON[22787]: (pam_unix) session opened for user root by (uid=0)
auth.log:Dec 12 09:15:01 ps17185 CRON[22787]: (pam_unix) session closed for user root
auth.log:Dec 12 09:15:01 ps17185 CRON[22792]: (pam_unix) session opened for user drook by (uid=0)
auth.log:Dec 12 09:15:01 ps17185 CRON[22788]: (pam_unix) session closed for user root
auth.log:Dec 12 09:15:04 ps17185 CRON[22792]: (pam_unix) session closed for user drook
auth.log:Dec 12 09:16:01 ps17185 CRON[23731]: (pam_unix) session opened for user root by (uid=0)
auth.log:Dec 12 09:16:01 ps17185 CRON[23731]: (pam_unix) session closed for user root
That shows a single instance of it for my user at 15 after the hour, which is correct. But I still don't trust it. Need to create a copy of the script with heavy debugging in it but not actually send the email and cron that.
--
Drew
|
Post #318,486
12/12/09 4:10:09 PM
|
Re: Nothing in /var/log/messages
is a mail server on the machine?
If not check the root user /var/mail/<user>
Any output not redirected by the script is sent to the local user, unless aliases redirect it.
|
Post #318,492
12/12/09 9:48:06 PM
|
Nope, not there either
Adding debugging calls now. How tedious ...
--
Drew
|
Post #318,506
12/13/09 11:06:45 AM
|
Check /etc/syslog.conf
You can adjust cron logging there. Adding
cron.debug /var/log/cron
will send cron's own debug output to /var/log/cron. Don't forget to recycle the syslog daemon after changing the configuration.
|
Post #318,510
12/13/09 12:34:07 PM
|
Good point.
Egads...
debug level wooo
Drew make sure you have your log rotation proper.
|
Post #318,513
12/13/09 1:32:30 PM
|
That would do it
Only entries in there for cron right now are
#cron.* /var/log/cron.log
and
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
So I'm not getting much info.
Assuming this can throw a huge amount of crap to disk in a hurry, what do I need to do to make sure I don't eat the disk before I can catch it?
--
Drew
|
Post #318,516
12/13/09 2:38:09 PM
|
set it for a single pass first, then debug
once you find the issue, then adjust the schedule.
|
Post #318,675
12/15/09 11:22:37 PM
|
Figured out the problem ... but not the solution (yet)
I set up the initial crontab, then made one or two changes to it. As a test, I just deleted my crontab, but my job still ran on schedule.
I've got my regular user and an admin user. I've checked that neither of those has a crontab, and I don't see one for root. (Which just means the root user for my virtual server doesn't have one. I don't actually have root on the physical box.)
So, is this something that I can fix, or do I need to submit a ticket to support?
--
Drew
|
Post #318,676
12/16/09 12:22:56 AM
|
*NOW* I've figured out the problem ... I am a dumbass
I never disabled the cronjob from the other host. As soon as the DNS changes propagated I started getting two runs. I had assumed since the server still thought it owned the domain that the job would never leave the box, but that doesn't seem to have been the case.
--
Drew
|
Post #318,696
12/16/09 4:06:09 PM
|
ICLRPD
*NOW* I've figured out the problem ... I am a dumbass
|