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 "\t\tDaily 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

 

posted @ 2015-06-05 23:25  little-snake  阅读(300)  评论(0编辑  收藏  举报