Koozali.org: home of the SME Server

Disk Usage Script

Offline robwellesley

  • *
  • 92
  • +0/-0
Disk Usage Script
« on: September 02, 2009, 03:20:18 AM »
Script assumes default SME7  fstab.


Highlite and copy this

################
#!/bin/sh
DOMAIN=`/sbin/e-smith/db configuration get DomainName`
SYSTEM=`/sbin/e-smith/db configuration get SystemName`

df -P | 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 90 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname).$DOMAIN as on $(date)" | \
    mail -s "ALERT: $usep% Disk Use on $SYSTEM.$DOMAIN" admin
  fi
done

##############

Using Putty or similar...

cd /etc/cron.daily
pico diskusage.sh
Right click will paste into putty

edit .... $usep -ge 90...  (default 90 will alert you at 90% usage, you can test it by making the 90 to be less than current disk use)
edit email recipient if you like (default is admin - can be anyone@anydomain)

CTRL X
Enter

Chmod 755 diskusage.sh

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Disk Usage Script
« Reply #1 on: September 02, 2009, 11:42:28 PM »
thank you but.. why don't you use logwatch? :-)
it will send a mail every day with disk usage and much more

Stefano

Offline robwellesley

  • *
  • 92
  • +0/-0
Re: Disk Usage Script
« Reply #2 on: September 02, 2009, 11:47:09 PM »
...cos I don't want a mail everyday ?

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Disk Usage Script
« Reply #3 on: September 02, 2009, 11:48:40 PM »
well, it could be a good reason, but I don't subscribe it ;-)