Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a command that can be run to verify that a users cron job has run successfully?

Platform is Ubuntu 8.04 LTS.

I have scripts in /home/useraccount/bin/

running

crontab -l

while logged in as user results in:

# m h  dom mon dow   command

@hourly /home/useraccount/bin/script_1

@hourly /home/locateruser/bin/script_2

I realize scripts could send email or write to a log with a timestamp, but wondering if there is just a way to verify it ran from the command line.

EDIT :

I ran

ps -ef|grep cron 

... and it shows

root      4358     1  0 Mar12 ?        00:00:00 /usr/sbin/cron

Not sure if this indicates it is running the jobs though....

share|improve this question
    
i think cron is always running. but if your cron jobs starts another process, then ps can be used to test whether said new process is running – gr33d Mar 30 '10 at 14:44
up vote 8 down vote accepted
grep scriptname /var/log/syslog
share|improve this answer
    
Thanks , this works. – CaseyIT Mar 30 '10 at 15:04

/var/log/cron

you can check to if its currently running with:

ps aux
share|improve this answer

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
share|improve this answer
    
This is good practice – Henry the Hengineer Sep 11 '12 at 22:48

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
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .