1753487 Members
4731 Online
108794 Solutions
New Discussion

crontab log

 
rajesh73
Super Advisor

crontab log

how to check my cron job running status

1 REPLY 1
Matti_Kurkela
Honored Contributor

Re: crontab log

If your cron job does not do anything to make itself easier to find, your options are to read the cron logfile (/var/adm/cron/log) or use the ps command (like "ps -fu <username>") to see if it is currently running.

 

If you don't redirect the standard output and/or standard error output of the cron job, the output will by default be mailed to you (if the mail system has default configuration, it will end up to your local email inbox file, /var/mail/<username>).

 

If your cron job is a script, you can make it easier to find by adding a command like this to the beginning of the script:

echo "$$" >/some/file.pid

 

This creates a pid file for the job, which allows you to make several checks:

  • If /some/file.pid exists, the cron job has been started at least once
  • the timestamp of the file will tell you the last time the cron job actually started
  • "ps -fp $(</some/file.pid)" will list the cron job process if it is still running
  • if you need some other script to know if the cron job is currently running, you can do it like this:
#!/bin/sh

# kill -0 only tests if a given PID exists
if kill -0 $(</some/file.pid); then
    echo "Yes, the job is still running."
else
    echo "No, the job is not running right now."
fi

 

MK