欢迎来到ArchitecTang的博客

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

posted @ 2020-01-16 18:01  ArchitecTang  阅读(147)  评论(0)    收藏  举报