#!/bin/bash
#######################
##modify by liugj
#at may 3 2011
#######################
#cp this script to /usr/local/monitor/
####take care this $PATH
. /etc/profile
p_name="tmss"
log=/home/liugj/moniter_logs/tmss/$p_name.log
####check the catalog and logfile
if [ ! -d $(dirname $log) ]
then
mkdir -p $(dirname $log)
touch $log
else
if [ ! -e $log ];then
touch $log
fi
fi
####clean up the log
line=`cat $log|wc -l`
if [ $line -gt 20000 ]
then
> $log
fi
####get ip
IP=`ifconfig|grep "inet addr"|grep -v "127.0.0.1" |awk '{print $2}'|awk -F: '{ORS=" ";print $2}'|awk '{print $1}'`
####judge the ria-run process
num=`netstat -antp|grep '\<9900\>'|wc -l`
if [ "$num" -gt "0" ]
then
echo "good";
log_good=$(date +%F"_"%T)"_"$p_name"_good_"$IP
##write log
echo $log_good >> $log
exit;
else
log_bad=$(date +%F"_"%T)"_"$p_name"_down_"$IP
##write log
echo $log_bad >> $log
#restart the process
##################
cd /home/TMSS
./tvs_gd_wht61 &
###################
####wait 10 sec
sleep 10
num=`netstat -antp|grep '\<9900\>'|wc -l`
if [ $num -gt 0 ]
then
log_body=$p_name"_"$IP"restarted_sucessfull_"$(date +%F"_"%T)
echo $log_body >> $log;
else
log_body=$p_name"_"$IP"restarted_failed_"$(date +%F"_"%T)
echo $log_body >> $log;
fi
fi
### */1 * * * * /home/liugj/moniter_3gss
####chmod +x moniter_3gss