Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script is used to send an e-mail notification if a certain partition
- # is running out of space. The message will be delivered if either the disk
- # usage in partition $PART is bigger than $MAXPERC or the amount of free
- # space is smaller than $MINFREE.
- #
- # Copyright (C) 2013, Henning Hollermann, laclaro@mail.com
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # percentage of disk usage, where mail should be sent
- MAXPERC=95 # percent
- # minimum free space, below e-mail should be sent
- MINFREE=15 # GB
- # mail destination
- MAIL_DESTINATION=admin@domain.com
- # surveilled partition
- PART=partition_name
- # free space in bytes
- FREE=`df |grep $PART | awk '{ print $4 }'`
- # percentage of disk space used and df-info line
- if [ -x /usr/bin/pydf ]; then
- USEPERC=`pydf --bw |grep $PART | awk '{ printf("%.0f",$5) }'`
- DF_LINE=`pydf --bw|awk '
- BEGIN { print " Disk space" };
- /'$PART'/{print " "$7 "\t" $3 "/" $2 " (" $5 "%)\tfree: "$4 "\n " $6};
- END { print ""}'`
- else
- USEPERC=`df -h |grep $PART | awk '{ print $5 }' | cut -d'%' -f1`
- DF_LINE=`df -h|awk '
- BEGIN { print " Disk space" };
- /Size|'$PART'/{print " "$2 "\t" $3 "\t" $4 "\t" $5 "\t" $6};
- END { print ""}'`
- fi
- echo $FREE $(($MINFREE*1000000))
- # if conditions met, send e-mail
- if [ $USEPERC -gt $MAXPERC -o $FREE -lt $(($MINFREE*1000000)) ]; then
- echo -e "
- Hello,\n
- this message was automatically created by $0.
- Partition $PART is running out of space (${USEPERC}% used).\n
- $DF_LINE\n
- You may clear the trash bin to free some space.\n
- `cat /tmp/motd-trashes`\n
- Best wishes, the administrator
- " | mail -s "$PART is running out of space" $MAIL_DESTINATION
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement