Monitoring your disk space with shell script | MyLiteratureTechLife.COM

Monitoring your disk space with shell script

December 13th, 2011 0 Comments






















If you are running a busy server with several customers, uploading alot of file then there is a chance that you get out of space without knowing. I was about to write a script for my server but then found it on a famous website.

#!/bin/sh
# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the (free avilable) percentage
# of space is >= 90%
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
# Linux shell script to watch disk space (should work on other UNIX oses )
# SEE URL: http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
# set admin email so that you can get email
ADMIN="me@somewher.com"
# set alert level 90% is default
ALERT=90
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  #echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" $ADMIN
  fi
done
nano -w /etc/cron.daily/diskalert

Paste above script and save file.

chmod +x /etc/cron.daily/diskkalert

Now script will run daily and send you email if disk space will be 90%

Related posts:

  1. The disk is offline because of policy set by Administrator
  2. Log rotation in plesk 8.x
  3. Cpanel / WHM /FTP/E-mail are showing incorrect or zero disk usage
  4. How to increase Qmail sending limit
 

If You Like This Post, Share it With Your Friends & Peers

Digg
stumbleupon
Delicious
facebook
twitter
reddit
rss feed bookmar
 

No Comment to “Monitoring your disk space with shell script”

  1. No Comment yet. Be the first to comment...

Leave your comment here:

*

Alexa Rank