linux系统状态监控脚本

#!/usr/bin/env bash
### Function:monitor linux system status
### Author:webjin
### [email protected]
### Date:2013-8-8
### Version:1.0
Html="/home/www/default/index.html"
Load=$(uptime | awk  -F"," '{print  $4 $5 $6}' | cut -d: -f2)
Ip=$(ifconfig | awk '/inet addr/ {print $2}' | grep -v '127.0.0.1' |  cut -d: -f2)
Df=$(df -P | awk '{print $4}' |  grep '^[0-9.]' | awk 'BEGIN{sum=0}{sum+=$1}END{print sum/1048576}')
Free=$(free -m | grep cache | awk ' /cache/{print $3}' | grep -v free)
Uptime=$(uptime | cut -d, -f1 | awk '{print $3,$4}' )
Date=$(date -d today +"%Y-%m-%d %T")
Ping=$(ping -W 1 -c 1 $Ip &> /dev/null && echo "ok" || echo "no")
cat > $Html << EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>服务器在线监控脚本</title>
</head>
<body>
<table border="1">
  <tr>
    <td>主机IP</td>
    <td>Ping</td>
    <td>在线时间</td>
    <td>磁盘空间</td>
    <td>剩余内存</td>
    <td>cpu负载</td>
  </tr>
  <tr>
    <td>$Ip</td>
    <td>$Ping</td>
    <td>$Uptime</td>
    <td>$Df G</td>
    <td>$Free M</td>
    <td>$Load</td>
  </tr>
</table>
<p>以上系统信息采集于$(date -d today +"%Y-%m-%d %T")</p>
</body>
</html>
EOF


你可能感兴趣的:(linux,status,System,监控,default)