shell 4
2020-06-20 21:52
696 查看
监控nginx 脚本,每20秒监测一次,如果进程数多于1000,重启nginx服务,重启5次失败后通知管理员,如果重启成功一分种后,进程数还是大于1000,通知运维
#!/bin/bash d=`date` c=`pgrep -l nginx | wc -l` check_nginx() { for ((i=1;i<=5;i++)) do /usr/local/nginx/sbin/nginx 2> /tmp/nginx.log if [ $? -eq 0 ] then echo "${d}nginx 重启${i}次成功" | mail -s "nginx 进程监控" 383xxxxx@qq.com break fi done } while : do if [ c -gt 1000 ] then check_nginx if [ $i -eq 5 ] then echo "${d}nginx 5次重启失败,请登录服务器处理" | mail -s "nginx 进程监控" 383xxxxxx@qq.com exit else sleep 60 c1=`pgrep -l nginx | wc -l` if [ c1 -gt 1000 ] then echo "${d}nginx重启后进行仍大于1000,请登录服务器处理" | mail -s "nginx 进程监控" 383xxxxx@qq.com exit fi fi fi sleep 20 done
相关文章推荐
- C语言获取Shell返回结果的实现方法
- shell整理(38)===凯撒加密和解密
- Nocatalog 下的RMAN 增量备份 shell脚本
- Linux下Shell脚本输出带颜色文字(转)
- [百晓生]-你可能不知道的shell
- adb shell mount -o remount,rw /firmware
- shell 重定向 知识
- shell 下的运算表达
- Android系统下好用的shell命令
- shell 参数传递
- CentOS 7 shell脚本_自动部署初始化(记录)
- shell脚本批量生成配置文件
- shell脚本案例
- 关于adb shell procrank提示procrank: not found的问题解决
- shell脚本与C语言数据类型基础知识
- shell 编程——for in 循环
- shell取字符串字串的操作
- shell脚本中一些特殊符号
- HDFS的shell操作
- 【SHELL】监控Nginx运行,Mysql主从运行,主从复制延迟