On Mon, 2014-04-14 at 09:10 -0400, Fred Smith wrote:
On Mon, Apr 14, 2014 at 09:20:09AM +0100, Arthur Dent wrote:
<snip>
> The test example I gave yesterday is in fact based on a real-life case.
> I have a job that runs hourly from cron. Occasionally this process fails
> (for reasons I won't bore the list with) and leaves a lock-file in place
> - a will then refuse to run again until someone (me) has cleaned up
> after it. The only way I even know that this has happened is accuse I
> have another little hourly cron job that checks for the presence of the
> lock-file and reports only if it exists.
>
> If I have to rely on the daily logwatch output it could conceivably be
> up to 23 hours before I even know that the job is not working...
I've used, in the past, a mechanism where the program controls its own
lock file, so it has control over what goes inside the file. (I dunno if
your app is simlar, or if it uses some system services to manage lockfiles.)
When starting up:
1. see if the lockfile exists
1a. Exists: open it, read its contents, which should be the PID of the
program that created it. see if a process of that PID is still running.
If so, silently exit. if the pid doesn't exist, delete the lock file
and go to step 2.
1b. if no lockfile, start normally.
2. normal start: create the lockfile, write your own PID into it.
3. program runs.
4. when program finishes, it removes the lockfile.
This lets the program determine, whenever it starts up, if it's a bogus lock
file, or if it isn't. If it no longer refers to a running process, it can
simply be deleted without causing any undue delays.
Thanks for that - I am going to look into fixing that at some point in
the future, but at the moment my workaround will suffice. It's not just
for that problem that I want to see cron output in email form. I have
lots of jobs run as my user (mark) and I want the email to to know when
they have completed etc.
I am tearing my hair out over this. I have read previous threads on the
subject, but most seem to relate to getting root mail. That works now
(thanks to Suvayu Ali) - putting:
# Person who should get root's mail
root: mark
into /etc/aliases did the trick for root cron jobs.
But I still don't get cron output for user mark.
I have MAILTO=mark at the top of my crontab file.
According to /var/log/cron the job has run and has produced output:
Apr 14 13:58:02 Zaphod CROND[8001]: (mark) CMD (~/scripts/croncheck.sh)
Apr 14 13:58:02 Zaphod CROND[7999]: (mark) CMDOUT (Please Note: That file does not exist)
Nothing appears in /var/spool/mail/mark though.
The exim logs show no evidence of having been bothered by cron...
2014-04-14 12:44:05 1WZfIy-0001xD-Mb <= fail2ban(a)example.com U=root P=local S=1988
2014-04-14 12:44:06 1WZfIy-0001xD-Mb => mark <root@Zaphod> R=procmail T=procmail
2014-04-14 12:44:06 1WZfIy-0001xD-Mb Completed
2014-04-14 13:08:35 Start queue run: pid=7745
2014-04-14 13:08:35 End queue run: pid=7745
2014-04-14 14:08:35 Start queue run: pid=8149
2014-04-14 14:08:35 End queue run: pid=8149
Note that the entry at 12:44 was the output from fail2ban which is
mailed to root (and thence to Mark). I then get that email.
So where does the output from cron jobs for normal users go?