User Tools

Site Tools


execution_time_and_notify

Check execution time and notify if exceed

One Liner

s=`date +%s`; /usr/local/bin/php index.php ; e=`date +%s`; if [ $(( $e - $s )) -gt 10 ];
then /usr/bin/mail -s "[Notice] `hostname` Time is More then 10 second" status@k2.com ; fi

Script

#!/bin/bash
# Monitor execution of process
 
export receipients="status@k2.com"
 
output=".BxJ04o1k2lcTURK"
 
notify(){
   for n in $receipients; do
      echo $1 | /usr/bin/mail -s "[Notice] `hostname` Time is More then 10 second" $n
   done
}
 
cd /usr/www/virtual/sf/www.xyz.com/
/usr/bin/time -h -p -o $output /usr/local/bin/php index.php >/dev/null 2>&1
count=0
 
for i in `cat $output | awk '{print $2}'`
do
case=`echo "$i > 10.0" | bc`
if [ $case -eq '1' ]
then
        count=1;
fi
done
if [[ count -eq '1' ]]
then
notify "index.php is taking more then 10 second to execute"
fi
 
rm $output
execution_time_and_notify.txt · Last modified: 2011/05/25 14:51 by k2patel