EDIT: Get the file here
There are many ways… For example, you can add this to your /etc/bash.bashrc file… Or create a command (Put these in a file, and after that, copy that to on of the directories in $PATH, which you can check those using ‘echo $PATH command).
I wrote this script, sometime ago (In an exam):
#!/bin/bash
#This script will send a warning to the administrator if 80% or more of the / is
used.
#By Adel Moin (AMLJ)
# $FSTDIG is the first digit of the amount of the partition which is used.
# $SECDIG is the second digit of the amount of the partition, which is used, if it’s ’%‘, then only a little amount of the partition is used, so there is no need to warn the user. Otherwise, more than 80% of the partition is used, and the user has to be warned.
# If $FULL is '100’, the partition is totally full, and the user needs to be worried.
# In case $ALARM is ‘true’, the warning mail will be sent.
FSTDIG=df -P / |tail -n1 |awk '{ print $5 }' |cut -b1
SECDIG=df -P / |tail -n1 |awk '{ print $5 }' |rev |cut -b1
FULL=df -P / |tail -n1 |awk '{ print $5 }'
if [ $FSTDIG == 8 ] && [ x$SECDIG != x'%‘ ]
then
ALARM=true
fi
if [ $FSTDIG == 9 ] && [ x$SECDIG != x’%‘ ]
then
ALARM=true
fi
if [ $FULL == 100 ]
then
ALARM=true
fi
if [ ’$ALARM' == ‘true’ ]
then
echo ‘80% or more of the / is used!’ |mail -s ‘WARNING!’ root
fi
exit 0
That will send a mail to root… You can add this if you want a message printed:
#!/bin/bash
#This script will print a message if more than 80% of / is full.
#By Adel Moin (AMLJ)
# $FSTDIG is the first digit of the amount of the partition which is used.
# $SECDIG is the second digit of the amount of the partition, which is used, if it’s ‘%’, then only a little amount of the partition is used, so there is no need to warn the user. Otherwise, more than 80% of the partition is used, and the user has to be warned.
# If $FULL is ‘100’, the partition is totally full, and the user needs to be worried.
# In case $ALARM is ‘true’, the warning mail will be sent.
FSTDIG=df -P / |tail -n1 |awk '{ print $5 }' |cut -b1
SECDIG=df -P / |tail -n1 |awk '{ print $5 }' |rev |cut -b1
FULL=df -P / |tail -n1 |awk '{ print $5 }'
if [ $FSTDIG == 8 ] && [ x$SECDIG != x'%‘ ]
then
ALARM=true
fi
if [ $FSTDIG == 9 ] && [ x$SECDIG != x’%‘ ]
then
ALARM=true
fi
if [ $FULL == 100 ]
then
ALARM=true
fi
if [ ’$ALARM' == ‘true’ ]
then
echo -en ‘\E[47;31m’“\033[1mMore than 80% of / is full\033[0m”
fi
exit 0
The script is a bit noobish, as I wrote it when I was kinda a noob! :)
But it’ll work….
Let me know if it had any probs… (Had to edit it… Also, the copy-paste made it a bit ruined, so although I tried to make it better, there might be still problems)
In which environment? Dekstop with GNOME, KDE, Xfce, LXDE, somethingdifferent? Or a server? What kind of warning do you like? A popup on the desktop? Or a mail?