Below mentioned is a ready to use Linux script to check the system partition size and alert if it has crossed configured threshold value. The script uses linux df command to capture the details . Copy the code below highlighted in blue , save it in a file and execute for output.
There is a threshold variable provided which you can customize as per requirement. If the average crosses the threshold , output displays red else in green.
#!/bin/sh
threshold=50
filesystems=`df -Ph | grep -v 'Filesystem' |grep -v '/dev/shm' |grep '%' |awk '{print $1}'`
for i in $filesystems
do
usage=`df -Ph |grep "$i " |awk '{print $5}' | tr -d "%"`;
name=`df -Ph |grep "$i " |awk '{print $6}'`
if [ $usage -gt $threshold ]
then
echo -e "\033[1;31mExceeded $threshold% -\t $name ($usage%) \033[0m"
else
echo -e "\033[1;32mNormal -\t $name($usage%)\033[0m"
fi
done
Hope it helps to some Linux beginners.
There is a threshold variable provided which you can customize as per requirement. If the average crosses the threshold , output displays red else in green.
#!/bin/sh
threshold=50
filesystems=`df -Ph | grep -v 'Filesystem' |grep -v '/dev/shm' |grep '%' |awk '{print $1}'`
for i in $filesystems
do
usage=`df -Ph |grep "$i " |awk '{print $5}' | tr -d "%"`;
name=`df -Ph |grep "$i " |awk '{print $6}'`
if [ $usage -gt $threshold ]
then
echo -e "\033[1;31mExceeded $threshold% -\t $name ($usage%) \033[0m"
else
echo -e "\033[1;32mNormal -\t $name($usage%)\033[0m"
fi
done
Hope it helps to some Linux beginners.