#!/bin/bash
date >> ./aliScriptDaemon.log
echo "========aliScriptDaemon.sh START========" >> ./aliScriptDaemon.log

cdrpid="aliScriptDaemon"
eventpid="aliScriptDaemon"

while true;do
#for aliNewCallResult.php
PROEVENT_NOW=`ps aux | grep aliNewCallResult | grep -v grep | wc -l`
if [ $PROEVENT_NOW -lt 15 ]; then
/usr/bin/nohup /usr/bin/php /var/www/html/asterCC/app/webroot/aliNewCallResult.php &
eventpid="$!";
date >> ./aliScriptDaemon.log
echo "aliNewCallResult.php Start-1, PID is $eventpid" >> ./aliScriptDaemon.log
echo "status is $?" >> ./aliScriptDaemon.log
fi

PROEVENT_STAT=`ps aux|grep aliNewCallResult |grep T|grep -v grep|wc -l`
if [ $PROEVENT_STAT -gt 0 ]; then
kill -9 $eventpid
sleep 2
/usr/bin/nohup /usr/bin/php /var/www/html/asterCC/app/webroot/aliNewCallResult.php &
eventpid="$!";
date >> ./aliScriptDaemon.log
echo "aliNewCallResult.php Start-2, PID is $eventpid" >> ./aliScriptDaemon.log
echo "status is $?" >> ./aliScriptDaemon.log
fi


#for aliCallResult.php
#PROEVENT_NOW=`ps aux | grep aliCallResult | grep -v grep | wc -l`
#if [ $PROEVENT_NOW -lt 5 ]; then
#/usr/bin/nohup /usr/bin/php /var/www/html/asterCC/app/webroot/aliCallResult.php &
#eventpid="$!";
#date >> ./aliScriptDaemon.log
#echo "aliCallResult.php Start-1, PID is $eventpid" >> ./aliScriptDaemon.log
#echo "status is $?" >> ./aliScriptDaemon.log
#fi

#PROEVENT_STAT=`ps aux|grep aliCallResult |grep T|grep -v grep|wc -l`
#if [ $PROEVENT_STAT -gt 0 ]; then
#kill -9 $eventpid
#sleep 2
#/usr/bin/nohup /usr/bin/php /var/www/html/asterCC/app/webroot/aliCallResult.php &
#eventpid="$!";
#date >> ./aliScriptDaemon.log
#echo "aliCallResult.php Start-2, PID is $eventpid" >> ./aliScriptDaemon.log
#echo "status is $?" >> ./aliScriptDaemon.log
#fi


#for aliReviewCallResult.php
#PROCDR_NOW=`ps aux | grep aliReviewCallResult | grep -v grep | wc -l`
#if [ $PROCDR_NOW -lt 3 ]; then
#/usr/bin/nohup /usr/bin/php /var/www/html/asterCC/app/webroot/aliReviewCallResult.php &
#cdrpid="$!";
#date >> ./aliScriptDaemon.log
#echo "aliReviewCallResult.php Start-1, PID is $cdrpid" >> ./aliScriptDaemon.log
#echo "status is $?" >> ./aliScriptDaemon.log
#fi

#PROCDR_STAT=`ps aux|grep aliReviewCallResult |grep T|grep -v grep|wc -l`
#if [ $PROCDR_STAT -gt 0 ]; then
#kill -9 $cdrpid
#sleep 2
#/usr/bin/nohup /usr/bin/php /var/www/html/asterCC/app/webroot/aliReviewCallResult.php &
#cdrpid="$!";
#date >> ./aliScriptDaemon.log
#echo "aliReviewCallResult.php Start-2, PID is $cdrpid" >> ./aliScriptDaemon.log
#echo "status is $?" >> ./aliScriptDaemon.log
#fi

sleep  30

done

