The Computer Oracle

Verify that a cron job has completed

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Track title: CC O Beethoven - Piano Sonata No 3 in C

--

Chapters
00:00 Verify That A Cron Job Has Completed
00:48 Accepted Answer Score 18
00:57 Answer 2 Score 4
01:09 Answer 3 Score 4
01:30 Answer 4 Score 1
01:44 Answer 5 Score 1
02:13 Thank you

--

Full question
https://superuser.com/questions/125697/v...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #ubuntu #script #cron

#avk47



ACCEPTED ANSWER

Score 18


grep scriptname /var/log/syslog



ANSWER 2

Score 4


/var/log/cron

you can check to if its currently running with:

ps aux



ANSWER 3

Score 4


To make sure a script completed successfully one should really use a temp file. Create it when the job starts and delete it when it finished. This also catches crashes and avoids running the same job again in case of errors.

#!/bin/bash

# check if there is already a temp file with suffix .myscript in /tmp,
# if file exists return with status of 666
[ -f /tmp/*.bla ] && exit 666

# create a temp file with suffix .myscript
TEMP_FILE=`mktemp --suffix .myscript`
touch $TEMP_FILE

#
# script stuff
#

# we are done, clean-up after ourselves
rm $TEMP_FILE



ANSWER 4

Score 1


You can also have results emailed to you.

30 3 * * * find /home/*/Maildir/.Spam/{new,cur}/ -type f -mtime +6 -delete| \
           mail -e -s "task #1 report" postmaster@example.com



ANSWER 5

Score 1


I've built a tool, http://cronitor.io, because I needed a solution to monitor a few cron jobs and wasn't happy with the existing options. It's free to monitor a single job, and there are paid plans for business use.

What's great about Cronitor is that you just give it a cron expression like */5 * * * M-W and you will be alerted if the job doesn't start on schedule, runs longer than expected, or overlaps itself.