Linux监控脚本

来源:互联网 发布:狙击模拟软件ios 编辑:程序博客网 时间:2024/06/10 22:40
while :doif [ -f "./mon_linux.sh" ]thenecho "进程开始运行"elseexit 1fi#!/bin/bash>result.tmp#set -x#version: 2.0export LC_ALL="en_US.UTF-8" server_info(){echo ================System basic informaion==============================#echo ======Time======#dateecho "hostname" is `/bin/hostname`echo "IP ADDRESS" is `/sbin/ifconfig em1|grep "inet addr:"|awk '{print $2,"/ "$4}' | awk -F ':' '{print $2}' | awk -F '/' '{print $1}' | sed 's/ .*//g'`HOST_NAME=`hostname`#dmidecode | grep -A10 "System Information$" |grep "Product Name:"|awk '{print $3,$4,$5}'##dmidecode | grep -A10 "System Information$" |grep "Serial Number:"|awk '{print "SN:",$3}'echo "CPU INFORMATION" is `cat /proc/cpuinfo|grep "name"|cut -d: -f2 |awk '{print "*"$1,$2,$3,$4}'|uniq -c`#echo "Physical memory number" is  `dmidecode | grep -A 16 "Memory Device$" |grep Size:|grep -v "No Module Installed"|awk '{print "*" $2,$3}'|uniq -c`echo "System version" is `cat /etc/issue | head -1`} OS_info(){echo "system running time" is `/usr/bin/uptime |awk '{print $3,$4}'`} performance_info(){echo "================System cpu&&memory information=========================================="cpu_usage=`top -b -n 1 |grep C[Pp][Uu] |grep id|awk '{print $5}'|awk -F "%" '{print $1}'`echo "CPU FREE PERCENT is $cpu_usage"mem_total=$(free -m |grep Mem|awk '{print $2}')mem_used=$(free -m |grep Mem|awk '{print $3}')echo "mem_rate" is `expr $mem_used/$mem_total*100|bc -l`Swap_total=$(free -m |grep Swap|awk '{print $2}')Swap_used=$(free -m |grep Swap|awk '{print $3}')echo "Swap_rate" is `expr $Swap_used/$Swap_total*100|bc -l`echo "================System process information=========================================="i=1ps aux | sort -nr -k3 | awk '{print $3,$NF}' |  head -10 | while read A Bdoecho "process $B cpu  usage is $A" i=$(($i + 1))donei=1ps aux | sort -nr -k4 |awk '{print $4,$NF}' | head -10 | while read A B doecho "process  $B memory use is  $A"i=$(($i + 1))done}sec_info(){echo "==============User logon  information====================="w | grep -v ^USER | grep -v ^" " | while read Adoecho "user logon information" is  $Adoneecho "==============disk  information====================="df -h | grep -i -v mount|  awk '{print $1,$(NF-1),$NF}' | while read  A B C  doif [ "$A" = "$C" ]thencontinueelse  echo "$C" usage is  "$B"fi  doneecho "==============dmesg  information====================="dmesg |grep fail | sort -u | while read Ado  echo "dmesg fail" is $Adonedmesg |grep error | sort -u |  while read Ado echo "dmesg error" is $Adone}system_hardware_config(){echo ===========================disk====================================df -H |awk "{OFS=\"\t\"}{ print \$1,\$2,\$3,\$4,\$5,\$6}"echo ===========================free====================================free |head -1 |awk "{OFS=\"\t\"} {print \$1,\$2,\$6}"free -m |awk "BEGIN{OFS=\"\t\"}{if (NR==2 ||NR==4 )print \$2,\$3,\$7}"} server_info>>result.tmpOS_info>>result.tmpperformance_info>>result.tmpsec_info>>result.tmpecho "run Ok"sleep 30done

0 0
原创粉丝点击