成功最有效的方法就是向有经验的人学习!

LINUX服务器巡检

#!/bin/bash
#Aut@Laomeng
#Server inspection report
AUT="Aut@Laomeng"
LMTIME=`date +%m/%d/%Y`
DATETIME=`date +%k:%M:%S`
LMHOSTNAME=`cat /etc/sysconfig/network |grep "HOSTNAME"|gawk -F= '{print $2}'`
NOWTIME=`date +"%H:%M:%S %m/%d/%Y"`
SYS_RUNTIME=`uptime |awk '{FS=""}{print $3}'`
LOG_USERS=`uptime |gawk '{print $4}'`
CPU_TYPE=`cat /proc/cpuinfo |head -5|tail -1 |gawk 'BEGIN{FS=":"}{print $2}'`
CPU_GESHU=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l`
CPU_CORE=`cat /proc/cpuinfo| grep "cpu cores"| uniq|awk 'BEGIN{FS=":"}{print $2}'`
CPU_IDLE=`vmstat 1 2 |sed -n '/[0-9]/p'|sed -n '2p'|gawk '{print $15}'`
CPU_LOAD=`uptime | gawk '{print $NF}'`
TOTAL_MEM=`free -m |head -2|tail -1 |gawk 'BEGIN{FS=" "}{print $2}'`MB
USEE_MEM=`free -m |head -2|tail -1 |gawk 'BEGIN{FS=" "}{print $3}'`MB
FREE_MEM=`free -m |head -2|tail -1 |gawk 'BEGIN{FS=" "}{print $4}'`MB
TEST_FILE=`dd if=/dev/zero of=testdb bs=64k count=4k oflag=dsync 2>&1 |tail -1|awk '{print $0}'|sed -n 's/(//p'|awk '{print "文件大小:"$3"MB  ","耗时:"$6"Seconds " "速度:"$8"MB/s "}'`
IPADDR=`ifconfig eth0 |egrep "inet addr" |awk '{FS=" "}{print $2}'|gawk -F: '{print $2}'`
IPNETMASK=`ifconfig eth0 |egrep "Mask"|gawk -F" " '{print $4}'|awk -F: '{print $2}'`
MASTER_sda=`df -h |head -2|tail -1|awk 'BEGIN{FS=" "}{print "分区:"$1 , $6 "容量:"$2, "使用:"$3, $5, "有效空间:"$4}'`
MASTER_sda1=`df -h |tail -2|head -1|awk 'BEGIN{FS=" "}{print "分区:"$1 , $6 "容量:"$2, "使用:"$3, $5, "有效空间:"$4}'`
SDA_SPACE="/dev/sda `fdisk -l |egrep -e "sda" |egrep "GB"  |head -1 |awk 'BEGIN{FS=" "}{print $3}'`GB"
SDB_SPACE="/dev/sdb `fdisk -l |egrep -e "sdb" |egrep "GB"  |head -2 |tail -1|awk 'BEGIN{FS=" "}{print $3}'`GB"
MASTER_DISK=`df -h |grep /dev/sda3|awk 'BEGIN{FS=" "}{print $1,$2}'`
MASTER_SPACE=`df -h |grep /dev/sda3|awk 'BEGIN{FS=" "}{print $5}'`
################################################
LMSQL="/usr/bin/mysql"
LUSER="root"
LPASSWORD="&&&&&&"
function Lexp()
{
$LMSQL -u$LUSER -p$LPASSWORD<< EOF
use asteriskcdrdb;
select count(*) from cdr;
quit
EOF
}
################################################
CDR_TOTAL_LINE=`Lexp|tail -1 |gawk '{print $1}'`
cd /var/lib/mysql
CDR_SPACE=`du -h asteriskcdrdb |awk '{print $1}'`
ONLINEEXTEN=`asterisk -rx "sip show peers"|tail -1 |awk '{print $5, $6}'|awk -F, '{print $1}'`
OFFLINEEXTE=`asterisk -rx "sip show peers"|tail -1 |awk '{print $7,$8}'`
TOTAL_CHANNELS=`asterisk -rx "core show channels"|tail -3|head -1`
TOTAL_CALLS=`asterisk -rx "core show channels"|tail -2|head -1`
MYSQL_STATUS=`/etc/init.d/mysqld status |awk '{print $0}'`
ASTERISK_STATU=` /etc/init.d/asterisk status |awk '{print $0}'`
[ -f /opt/checkreport.html ] && rm -rf /opt/checkreport.html
#Create htmll Report
echo "<!doctype htmll>" > /opt/checkreport.html
echo "<htmll lang=\"en\">" >>/opt/checkreport.html
echo "<head>" >/opt/checkreport.html
echo "<meta charset=\"UTF-8\">" >> /opt/checkreport.html
echo " <title>Document</title>" >> /opt/checkreport.html
echo "<style>" >>/opt/checkreport.html
echo ".tab th,td {border:1px solid #181320;}" >>/opt/checkreport.html
echo "body{background:#BBDAEE;color:#012101;}" >> /opt/checkreport.html
echo "</style>" >>  /opt/checkreport.html
echo " </head>" >>  /opt/checkreport.html
echo " <body >" >>  /opt/checkreport.html
echo "<table class=\"tab\">" >>  /opt/checkreport.html
echo " <th colspan=5;>服务巡检报告</th>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>作者</td>">>/opt/checkreport.html
echo "<td  colspan=\"3\" >$AUT</td>">>/opt/checkreport.html
echo "<td  >$DATETIME $LMTIME </td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>主机名</td>">>/opt/checkreport.html
echo "<td colspan="3">$LMHOSTNAME</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>当前系统时间</td>">>/opt/checkreport.html
echo "<td colspan="3" >$NOWTIME </td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>系统运行时间</td>">>/opt/checkreport.html
echo "<td colspan=\"3\" >$SYS_RUNTIME (天数或小时) </td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>登录用户数</td>">>/opt/checkreport.html
echo " <td colspan=\"3\" >$LOG_USERS </td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>CPU信息</td>">>/opt/checkreport.html
echo "<td  colspan=\"3\" >CPU型号:$CPU_TYPE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>CPU信息</td>">>/opt/checkreport.html
echo "<td  colspan=\"3\" >CPU个数:$CPU_GESHU</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>CPU信息</td>">>/opt/checkreport.html
echo "<td  colspan=\"3\" >CPU核数:$CPU_CORE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>CPU空闲值</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$CPU_IDLE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>CPU负载</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$CPU_LOAD </td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>总内存</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$TOTAL_MEM</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>内存使用情况</td>">>/opt/checkreport.html
echo "<td >使用中:$USEE_MEM</td>">>/opt/checkreport.html
echo "<td colspan=\"2\">未使用:$FREE_MEM</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>磁盘I0速度</td>">>/opt/checkreport.html
echo "<td   colspan=\"3\">$TEST_FILE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>网卡信息</td>">>/opt/checkreport.html
echo "<td  colspan=\"1.5\">IP:$IPADDR </td>">>/opt/checkreport.html
echo " <td  colspan=\"1.5\">掩码:$IPNETMASK</td>">>/opt/checkreport.html
echo "<td ></td>">>/opt/checkreport.html
echo "<td >$DATETIME $LMTIME </td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>磁盘空间</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$SDA_SPACE $SDB_SPACE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>磁盘空间</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$MASTER_sda</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>磁盘空间</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$MASTER_sda1</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>话单</td>">>/opt/checkreport.html
echo "<td  >话单总数:$CDR_TOTAL_LINE</td>">>/opt/checkreport.html
echo "<td  colspan="2" >话单容量:$CDR_SPACE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME </td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>在线分机</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$ONLINEEXTEN</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>离线分机</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$OFFLINEEXTE</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>当前活动通道</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$TOTAL_CHANNELS</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>当前通话数量</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$TOTAL_CALLS</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>数据库状态</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$MYSQL_STATUS</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "<tr>">>/opt/checkreport.html
echo "<td>软交换状态</td>">>/opt/checkreport.html
echo "<td colspan=\"3\">$ASTERISK_STATU</td>">>/opt/checkreport.html
echo "<td>$DATETIME $LMTIME</td>">>/opt/checkreport.html
echo "</tr>">>/opt/checkreport.html
echo "</table>">>/opt/checkreport.html
echo "</body>">>/opt/checkreport.html
echo "</htmll>">>/opt/checkreport.html
cd /opt/
mv checkreport.html  /var/www/html
echo "使用方法:http://IP地址或IP地址和端口/checkreport.html"

赞(0) 打赏
未经允许不得转载:陈桂林博客 » LINUX服务器巡检
分享到

大佬们的评论 抢沙发

全新“一站式”建站,高质量、高售后的一条龙服务

微信 抖音 支付宝 百度 头条 快手全平台打通信息流

橙子建站.极速智能建站8折购买虚拟主机

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册