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
  • 相关阅读:
    模态框获取内容jQuery
    jQuery支持链式编程,一句话实现左侧table页+常用筛选器总结
    jquery实现全选、取消反选、加JavaScript三元运算(三种法法实现反选)
    用dom1来实现,根据光标移动自动给表单加上背景色,光标移开自动去除背景色
    JavaScript两种创建标签的的方法,实现点击按钮让text自增
    vue前端路由搜索功能实现
    pycharm配置vue
    QT全局事件和绑定
    mysql事务、锁
    web前端上传文件按钮自定义样式
  • 原文地址:https://www.cnblogs.com/little-snake/p/4555796.html
Copyright © 2011-2022 走看看