cdr-start.sh 1.19 KB
#!/bin/bash

file_name="/var/log/cdr-run.log"                   # 日志文件
pid=0

proc_num()                                              # 计算进程数
{
        num=`ps -ef |  grep "CDR_run" | grep -v grep |  wc -l`
        return $num
}

proc_id()                                               # 进程号
{
        pid=`ps -ef |  grep "CDR_run" | grep -v grep | awk '{print $2}'`
}

proc_num
number=$?
echo $number >> $file_name
if [ $number -eq 0 ]                                    # 判断进程是否存在
then
	source /etc/profile && source /root/.bash_profile && source /root/.bashrc
	export PGPASSWORD=ccc
	result=`psql -h 172.29.1.11 -p 5432 -U ccc  -d ipcc -c "select 1" | grep "\-\-\-\-"`
	if [ ${#result} -gt 0 ]
	then
		ulimit -s 240
        	/opt/cdr/run.sh start                 # 重启进程的命令,请相应修改
	else
		echo "pgpool down but postgresql haven't start now" >> $file_name
	fi
        text=`date`
        hn=`hostname`
        #mail -s "$hn === $text, freeswitch restart" smithlp_2.0@163.com
        proc_id                                         # 获取新进程号
        echo ${pid}, `date` >> $file_name               # 将新进程号和重启时间记录
fi