Running Cron Jobs

Need a list of the currently running cron jobs? Then try this:

#!/usr/bin/sh

cronpid=`ps -ef | grep cron | grep -v pts | awk '{print $2}'`
# Following line needs curly braces because of the underscore
outfile="/tmp/${USER}_$cronpid.txt"
echo "Cron running under following PID: $cronpid"
ps -ef | grep $cronpid | grep -v pts | grep -v /usr/sbin/cron > $outfile
jobcount=`cat $outfile | wc -l`
if [ $jobcount -eq 0 ]; then
  echo "There are no jobs running at present"
else
  echo "Running cron jobs:"
  cat $outfile
  echo "Number of running jobs: $jobcount"
  rm $outfile
fi

This works well for me on the following:

  • AIX 7.1
  • Oracle Linux 7
  • CentOS 6: needed some changes because it has sh in a different location as well as both crond and anacron