Hi Everyone,
Just in need of your help again, I have managed to get a script to check the linux disk usage stuff. But wanted to tweak it little more to get the desired output.
Requirement:
Now its querying only one mount point, As its not saving in array instead calling it as variables. So i need each and every mount point to be check for its usage.
example mount points:
/
/dev/shm
/boot
/var
#!/bin/bash
LIMIT='80'
#Here we declare variable LIMIT with max of used space
DIR="( $(df -Ph | column -t | awk '{print $6}' | grep -v Mounted) )" -------- here everything is saving as single variable as the output is a 5th column; but i need that to be processed line by line in the below for loop.
#Here we declare variable DIR with name of directory
MAILTO=' xyxz@abc.com'
#Here we declare variable MAILTO with email address
SUBJECT="$DIR disk usage"
#Here we declare variable SUBJECT with subject of email
MAILX='mailx'
#Here we declare variable MAILX with mailx command that will send email
which $MAILX > /dev/null 2>&1
#Here we check if mailx command exist
if ! [ $? -eq 0 ]
#We check exit status of previous command if exit status not 0 this mean that mailx is not installed on system
then
echo "Please install $MAILX"
#Here we warn user that mailx not installed
exit 1
#Here we will exit from script
fi
#To check real used size, we need to navigate to folder
for i in $DIR
do
USED=$(df -Ph $i | awk '{print $5}' | sed -ne 2p | cut -d"%" -f1)
done
#This line will get used space of partition where we currently, this will use df command, and get used space in %, and after cut % from value.
if [ "$USED" -gt "$LIMIT" ]
#If used space is bigger than LIMIT
then
sudo du -sh ${DIR}/* | $MAILX -s "$SUBJECT" "$MAILTO"
#This will print space usage by each directory inside directory $DIR, and after MAILX will send email with SUBJECT to MAILTO
fi
-
Thiyags.