deeejay

Bash - Check DF of server and email notification

Apr 13th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1.     #!/bin/sh
  2.     # Shell script to monitor or watch the disk space
  3.     # It will send an email to $ADMIN, if the (free avilable) percentage
  4.     # of space is >= 95%
  5.     # -------------------------------------------------------------------------
  6.     # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
  7.     # This script is licensed under GNU GPL version 2.0 or above
  8.     # -------------------------------------------------------------------------
  9.     # This script is part of nixCraft shell script collection (NSSC)
  10.     # Visit http://bash.cyberciti.biz/ for more information.
  11.     # ----------------------------------------------------------------------
  12.     # Linux shell script to watch disk space (should work on other UNIX oses )
  13.     # SEE URL: http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
  14.     # set admin email so that you can get email
  15.     ADMIN="email1@your_company.com, email2@your_company.com"
  16.     # set alert level 95% is default
  17.     ALERT=95
  18.     df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
  19.     do
  20.     #echo $output
  21.     usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
  22.     partition=$(echo $output | awk '{ print $2 }' )
  23.     if [ $usep -ge $ALERT ]; then
  24.     echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)
  25.  
  26. FTP into your_server_name or ip_address:
  27. Enter instructions here to delete files or whatever and make sure not to delete this pipe --> |
  28.    mail -s "Alert: Almost out of disk space $usep" $ADMIN
  29.    fi
  30.    done
Advertisement
Add Comment
Please, Sign In to add comment