#!/bin/sh
# Adapted from this itworld.com article, "Am I being run by cron?":
#        http://www.itworld.com/Comp/3380/nls_unixcron041209/index.html
#        CRON_PID=$(pgrep -x cron -u $USER)
CRON_PIDS=$(pgrep -x cron)
GRANDPARENT_PID=$(ps -eo ppid,pid | grep " $PPID$" | awk '{print $1}')

echo "cron:$CRON_PIDS"
echo "gpid:$GRANDPARENT_PID"

# for CRON_PID in $CRON_PIDS; do
# if [ "$CRON_PID" == "$GRANDPARENT_PID" ]
if [[ $(echo "$CRON_PIDS" | grep "$GRANDPARENT_PID") ]]
then echo I am being run through cron
else echo I am NOT being run through cron
fi
# done
