GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
!#/bin/sh
USED=$(df /home| tail -n 1 | awk '{print $4}' | cut -d '%' -f 1)
if [ ${USED} > 90 ]
then
echo "${USED} is greater than 90"
else
echo "${USED} is less than 90"
fi
#!/bin/bash
rm ~/latest_problem_with_disk_space
for i in `df -h | grep -v capaci | awk '{print $5}' | cut -d% -f1` ; do if [ $i -lt 90 ]; then echo "good" ; else echo "we have a problem on `df -h | grep $i `" >> ~/latest_problem_with_disk_space ; fi ; done
if [ -e ~/latest_problem_with_disk_space ] ; then mailx -s "FileSystem Full alert" your_email@yourcompany.com < ~/latest_problem_with_disk_space ; fi
Last edited by Blinker_Fluid; 05-22-2009 at 09:56 AM.
That won't helped. The message is coming for each mount point.
cat latest_problem_with_disk_space
we have a problem on Filesystem Size Used Avail Use% Mounted on
we have a problem on /dev/cciss/c0d0p8 1008M 721M 236M 76% /
we have a problem on /dev/cciss/c0d0p1 256M 36M 221M 14% /boot/efi
we have a problem on none 6.0G 0 6.0G 0% /dev/shm
40G 6.0G 32G 16% /edidev
we have a problem on /dev/cciss/c0d0p6 2.0G 1.3G 665M 66% /home
we have a problem on /dev/cciss/c0d0p5 9.9G 763M 8.6G 8% /opt
we have a problem on /dev/cciss/c0d0p7 2.0G 267M 1.7G 14% /tmp
138G 117G 14G 90% /dwtest01
138G 4.0G 127G 4% /dwdev06
we have a problem on /dev/cciss/c0d0p3 9.9G 2.7G 6.7G 29% /usr
we have a problem on /dev/cciss/c0d0p4 9.9G 382M 9.0G 4% /var
we have a problem on 138G 117G 14G 90% /dwtest01
we have a problem on 138G 118G 13G 91% /dwtest02
we have a problem on 138G 122G 9.5G 93% /dwtest03
we have a problem on 138G 120G 12G 92% /dwtest04
we have a problem on 138G 125G 6.5G 96% /dwtest05
138G 126G 5.7G 96% /dwtest06
138G 96G 36G 73% /dwdev02
we have a problem on 138G 125G 6.5G 96% /dwtest05
138G 126G 5.7G 96% /dwtest06
138G 96G 36G 73% /dwdev02
we have a problem on /dev/cciss/c0d0p8 1008M 721M 236M 76% /
138G 130G 850M 100% /dwdev04
we have a problem on marlins:/intfdata 270G 169G 95G 65% /intfdata
we have a problem on 138G 47G 84G 36% /dwdev01
At present, I am on a Solaris system where a fairly longwinded awk as below does it. It should work for all distros.
Essentilly, `DF` TAKES ALL BLOCKS AS 512 bytes. This is useful to report in megabytes (1048576 bytes). The awk computes the percentage and based on your threshold, the results are filtered and piped to your mail programme.
In Solaris, this comes as /usr/bin/dfspace and is a shell script.
It's returning the mountpoint also which is confusing the script. It should just return the percent minus the percent sign. I believe you were closer when you had
except in the script just return the $4 value that showed the % filled.
I took what you had earlier and modified to what I believe would work.
Code:
#!/bin/bash
rm ~/latest_problem_with_disk_space
for i in `df -kh|grep -v cciss|grep -v intfdata|grep -v Available|grep -v none|grep -v stage|awk '{print $4}'|sed -e 's/%//g' -e '1,2d'` ; do if [ $i -lt 90 ]; then echo "good" ; else echo "we have a problem on `df -h | grep $i `" >> ~/latest_problem_with_disk_space ; fi ; done
if [ -e ~/latest_problem_with_disk_space ] ; then mailx -s "FileSystem Full alert" your_email@yourcompany.com < ~/latest_problem_with_disk_space ; fi
Thanks lot Blinker Fluid. It is working fine. The output is given below.
cat latest_problem_with_disk_space
we have a problem on 138G 117G 14G 90% /dwtest01
we have a problem on 138G 118G 13G 91% /dwtest02
we have a problem on 138G 122G 9.5G 93% /dwtest03
we have a problem on 138G 120G 12G 92% /dwtest04
we have a problem on 138G 125G 6.5G 96% /dwtest05
138G 126G 5.7G 96% /dwtest06
138G 96G 36G 73% /dwdev02
we have a problem on 138G 125G 6.5G 96% /dwtest05
138G 126G 5.7G 96% /dwtest06
138G 96G 36G 73% /dwdev02
we have a problem on /dev/cciss/c0d0p8 1008M 721M 236M 76% /
138G 130G 850M 100% /dwdev04
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.