Disk usage
#!/bin/sh |
2 | # set -x |
3 | # Shell script to monitor or watch the disk space |
4 | # It will send an email to $ADMIN, if the (free available) percentage of space is >= 90%. |
5 | # ------------------------------------------------------------------------- |
6 | # Set admin email so that you can get email. |
7 | ADMIN="root" |
8 | # set alert level 90% is default |
9 | ALERT=90 |
10 | # Exclude list of unwanted monitoring, if several partions then use "|" to separate the partitions. |
11 | # An example: EXCLUDE_LIST="/dev/hdd1|/dev/hdc5" |
12 | EXCLUDE_LIST="/auto/ripper" |
13 | # |
14 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
15 | # |
16 | function main_prog() { |
17 | while read output; |
18 | do |
19 | #echo $output |
20 | usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1) |
21 | partition=$(echo $output | awk '{print $2}') |
22 | if [ $usep -ge $ALERT ] ; then |
23 | echo "Running out of space "$partition ($usep%)" on server $(hostname), $(date)" | |
24 | mail -s "Alert: Almost out of disk space $usep%" $ADMIN |
25 | fi |
26 | done |
27 | } |
28 | if [ "$EXCLUDE_LIST" != "" ] ; then |
29 | df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | main_prog |
30 | else |
31 | df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}' | main_prog |
32 | fi |
0 Comments
Post a Comment