Usually when a cron job crash, it will leave some error messages in the log.
We run shell script and some java program with cron job. Recently we found some weird thing out from the log. Obviously the program was either crashed or killed because there is a program lock we set when the program was initialed, which was not released. We guess the program was killed because the log of the program didn't show the finish message.
Who can possibly killed the job and how can I get notified through email when a cron job is dead?
EDIT: I don't want the crontab way to receive email because it just push every standard output to the email. In my case there are a lot of other system output from different program because some of them ain't using log4j or they are echo by shell script. Because there are many users in the system, we can't require all the users to manage their program's standard output.
|| echo $?
to detect crashes / kills as per the question, only to detect non-signal exits which are silent but do not return EXIT_SUCCESS (0). The latter are unusual, because they also wouldn't show up if you had run the command from an interactive shell. (Might be useful to check for weird java programs or something though). – sourcejedi Oct 16 '18 at 20:36/path/to/myprogram
as the job, and the shell implements the common exec-the-last-command optimization, and the program dies from a signal, then nothing will print any message. The only trace of the death will be the notice from cron containing the program's exit status. – Gilles 'SO- stop being evil' Oct 16 '18 at 20:41echo "sleep 10" | bash
. It turns out this behaves differently from bothbash -c 'sleep "10"'
- which is what I should have tested - and e.g.echo "sleep 10" | dash
, which I also should have tested. – sourcejedi Oct 16 '18 at 21:04