zoukankan      html  css  js  c++  java
  • monitor system

     1 #!/bin/bash
     2 #
     3 #Snapshot_Stats - produces a report for system stats
     4 # This report will mail to root.
     5 # Command :free,uptime,exec
     6 #############################################################
     7 #Set Script Variables
     8 #
     9 DATE=`date +%d"-"%m"-"%Y`
    10 DISK_TO_MONITOR="/dev/sda1 /dev/sda2"
    11 MAIL=`which mail`
    12 MAIL_TO=root
    13 REPORT=/home/ach/data-file/monitor-system$DATE.rpt
    14 #
    15 ################################################################
    16 #Create Report File
    17 #
    18 exec 3>&1 # Save file descriptor
    19 #
    20 exec 1> $REPORT # direct output to rpt file.
    21 ###############################################################
    22 #
    23 echo
    24 echo -e "		Daily System Report"
    25 echo
    26 #
    27 ###############################################################
    28 #Date Stamp the Report
    29 #
    30 echo "Today is $DATE"
    31 echo
    32 #
    33 ###############################################################
    34 # 1) Gather System Uptime Statistics
    35 #
    36 echo -e "System has been c"
    37 uptime | sed -n '/,/s/,/ /gp' |
    38 gawk '{
    39 if ($4 == "day" || $4 =="days")
    40 {print $2,$3,$4,$5}
    41 else
    42 {print $2,$3}
    43 }'
    44 #
    45 ##############################################################
    46 # 2) Gather Disk Usage Statistics
    47 #
    48 echo
    49 for DISK in $DISK_TO_MONITOR    #loop to check disk space
    50 do
    51 echo -e "$DISK usage : c"
    52 df -h $DISK | sed -n '/% //p' | gawk '{print $5}'
    53 done
    54 #
    55 ###################################################################
    56 # 3)Gather Memory Usage Statistics
    57 #
    58 echo
    59 echo "Memory Usage :"
    60 #
    61 free | sed -n '2p' |
    62 gawk 'x = int(($3 / $2)*100)
    63 {print x}' |
    64 sed 's/$/%/'
    65 echo
    66 #
    67 #
    68 ##################################################################
    69 # 4) Gather Number of Zombie Processes
    70 #
    71 echo
    72 ZOMBIE_CHECK=`ps -al | gawk '{print $2,$4}' | grep Z`
    73 #
    74 if [ "$ZOMBIE_CHECK" = "" ]
    75 then
    76 echo "No Zombie Process on System at this Time."
    77 else
    78 echo "Current System Zombie Processes"
    79 ps -al | gawk '{print $2,$4}' | grep Z
    80 fi
    81 echo
    82 #
    83 ###################################################################
    84 # Restore File Descriptor & Mail Report
    85 #
    86 exec 1>&3 # Restore output to STDOUT
    87 #
    88 $MAIL -s "System Statistics Report for $DATE" $MAIL_TO < $REPORT
    89 #
    90 ###################################################################
    91 # Clean up
    92 #
    93 #rm -f $REPORT
    94 #
    95 #END
  • 相关阅读:
    后台架构设计—数据存储层
    Linux应用程序基础
    Linux文件管理命令笔记
    CentOS7搭建LAMP实战
    (ospf、rip、isis、EIGRP)常见的动态路由协议简介
    python while 循环语句
    获取linux帮助命令
    破解linux虚拟机的密码
    gawk编程语言
    MySQL触发器在PHP项目中用来做信息备份、恢复和清空的方法介绍
  • 原文地址:https://www.cnblogs.com/little-snake/p/4555796.html
Copyright © 2011-2022 走看看