shell 脚本 实现进程监控
#!/bin/sh
host_dir=/home/www/computer-vision
worker=1
for((i=1;i<= ${worker} ;i++));
do
proc_name="ASES${i}"
file_name="monitor.log"
pid=0
proc_num()
{
num=`ps -ef | grep $proc_name | grep -v grep | wc -l`
return $num
}
proc_id()
{
pid=`ps -ef | grep $proc_name | grep -v grep | awk '{print $2}'`
}
proc_num
number=$?
if [ $number -eq 0 ]
then
`rm -rf ${host_dir}/${proc_name}`
cp -rf ${host_dir}/ASES ${host_dir}/${proc_name}
cd $host_dir/${proc_name}/
mv ASES_p0 ${proc_name}
nohup ./${proc_name} &
echo 'start'
proc_id
echo ${pid},${proc_name} `date` >> $host_dir/$file_name
fi
done