标签:磁盘 com 脚本 ns3 ifconf add lin sed uname
#!/bin/bash echo "1. 对服务器硬件的监控" echo " 能够对服务器CPU进行监控,并输出CPU的信息" cpu=`cat /proc/cpuinfo |head -n 17` echo "CPU的信息为$cpu" echo "=========================================" echo " 2.能够对服务器内存进行监控,并输出内存剩余使用率信息" mem_total=`free -m |grep m|awk ‘{print $2}‘` echo "内存总量$mem_total" mem_used=`free -m |grep m|awk ‘{print $3}‘` echo "内存使用$mem_used" mem_free=`free -m |grep m|awk ‘{print $4}‘` echo "内存剩余$mem_free" residue=`free -m |grep m|awk ‘{print $4/$2*100"%"}‘ echo "内存剩余使用率$residue"` echo "=========================================" echo "3.能够对服务器网络进行监控,检测网络是否通畅,并输出结果" ping -c 1 www.baidu.com >/dev/null if [ $? -eq 0 ];then echo "network it‘s ok" else echo "please check network!!!!" fi echo "=========================================" echo "4.能够对服务器服务进行监控,比如ftp服务,mysql服务,并输出结果" netstat -anpt | grep mysql if [ $? -eq 0 ];then echo "mysql 正在启动" else echo "mysql 没有启动" systemctl start mariadb echo "mysql 开启了" fi echo "=========================================" echo "5.能够对文件系统进行查,查看使用率是否达到80%,并输出结果" dh_used=`df -h |awk ‘{if ($5>80) print $5}‘ |sed ‘1d‘` echo "使用率达到80的为:$dh_used" echo "=========================================" echo "6.能够在出现异常的时候通过邮件发送报警信息" df -h |awk ‘{if ($5>80) print $5}‘ |sed ‘1d‘ if [ $? -eq 0 ];then echo "使用率没有超过的80%" else echo "使用率超过80%" yum -y install mailx > /dev/null echo "please check disk"| mail -s "出现异常" 1423593121@qq.com fi echo "=========================================" echo "7.对磁盘读写进行监控,并输出结果" yum -y install sysstat >/dev/null iostat echo "=========================================" echo "8.对环境变量进行监控并输出结果" echo "将环境变量重新定向到目标" env >/opt/env md5sum /opt/env >/opt/env.md5 md5sum -c /opt/env.md5 >/dev/null if [ $? -eq 0 ];then echo "环境变量没有发生变化" else echo "环境变量发生变化,快及时处理" fi echo "=========================================" echo "9.检查操作系统的kernel信息并输出结" kernel=`uname -a` echo "系统的kernel的信息为:$kernel" echo "=========================================" echo "10.检查操作系统版本,并输出结果" linux=`cat /etc/redhat-release` echo "系统版本信息为: $linux" echo "=========================================" echo "11.查看网络统计信息并输出结果" addr=`ifconfig ens33 |grep netmask |awk ‘{print $2}‘` echo "网络ip为$addr" RX=`ifconfig ens33 |grep RX |head -n1|awk ‘{print $6}‘|awk -F ‘(‘ ‘{print $2}‘` echo "网卡流入量$RX" TX=`ifconfig ens33 |grep TX |head -n1|awk ‘{print $6}‘|awk -F ‘(‘ ‘{print $2}‘` echo "网卡流出量$TX" echo "=========================================" echo "12.查看所有进程,并输出信息" ps aux echo "=========================================" echo "9.检查操作系统的kernel信息并输出结" kernel=`uname -a` echo "系统的kernel的信息为:$kernel" echo "=========================================" echo "13.检测公司网站www.baidu.com是否在运行,在运行则提示信息" curl=`curl -l -m 10 -o /dev/null -s -w %{http_code} www.baidu.com` if [ $curl -eq 200 ];then echo "网站正常" else echo "网站不正常" fi echo "========================================="
标签:磁盘 com 脚本 ns3 ifconf add lin sed uname
原文地址:https://www.cnblogs.com/wendyluo/p/13149396.html