#!/bin/bash # process_timer.sh # run this through cron every 5 or 10 minutes to keep track of when a long duration process completed. # remember to remove it from cron after process completes # Edit this variable. # This variable needs to be a unique name or part of a name of the process you want to test # As it displays in process output (i.e. ps aux) my_process="erase" # if this script is being run outside cron, inform user tty -s is_tty=$? if [ $is_tty = "0" ] ; then echo "Is tty. Not running in cron." elif [ $is_tty -gt "0" ] ; then echo "Is NOT tty. Running in cron." fi my_process="erase" my_output="/tmp/donetime.txt" if ps aux | grep -v 'grep' | grep -q $my_process; then echo "$my_process is still running" now=`date` echo "$now \"$my_process\" is still running" >> $my_output else now=`date` date echo -n "Process \"$my_process\" completed at: " >> $my_output echo $now >> $my_output fi exit