Linux 服务守护脚本
#!/bin/bash
path=/var/log
log=${path}/httpd-mysql.log
name=(httpd mysql)
exs_init[0]="systemctl restart httpd"
exs_init[1]="systemctl restart mysqld"
for ((i=0; i<2; i++)); do
echo "检查${name[i]} 进程是否存在"
ps -ef|grep ${name[i]} |grep -v grep
if [ $? -eq 0 ]; then
echo "`date +"%Y-%m-%d %H:%m:%s"` ${name[$i]} is running with pid $PID" >> ${log}
else
$(${exs_init[i]})
echo "`date +"%Y-%m-%d %H:%m:%s"` ${name[$i]} start success" >> ${log}
fi
done