LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 05-18-2009, 07:28 AM   #1
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Rep: Reputation: 0
Mount point space


Hi All,

I would like to write a shell scripts which sends the mail when the mount point filled the 90 percent space.

cat test.sh
#!/bin/ksh
timestamp=`date +"%Y_%m_%d"`
LOG=/stage/scripts/space_usage.log
FS=' ' # field separator
#df -k|awk '{print $4,$5,$6}' > /tmp/test.txt
#df -k|awk '{print $4,$5,$6}'|sed 's/%/ /g' > /tmp/test.txt
#df -kh |awk '{print $4," ",$5}'|sed -e 's/%//g' -e '1,1d' > /tmp/test.txt
df -kh|grep -v cciss|grep -v intfdata|grep -v Available|grep -v none|grep -v stage|awk '{print $4,$5}'|sed -e 's/%//g' -e '1,1d' > /tmp/test.txt
cat /tmp/test.txt | while read string; do
percent_used=`echo "$string" |awk -F' ' '{print $1}'`
mount_point=`echo "$string" |awk -F' ' '{print $2}'`
echo "percent used "
echo $percent_used
echo "mount point "
echo $mount_point
if [ $percent_used > 90 ]
then
printf "\n $percent_used is greater than 90 \n"
else
printf "\n $percent_used is smaller than 90 \n"
fi
done
rm /tmp/test.txt

The above if condition is not working fine. It seems due to spaces. Can any one help on this.
 
Old 05-18-2009, 10:44 AM   #2
Dudydoo
Member
 
Registered: Sep 2003
Location: UK
Distribution: I use 'em all ;-)
Posts: 275

Rep: Reputation: 38
Seems rather long winded:

Code:
!#/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
 
Old 05-18-2009, 11:11 AM   #3
/dev/me
Member
 
Registered: May 2008
Distribution: Slackware 13
Posts: 116

Rep: Reputation: 20
Even shorter
Code:
if [ $(/bin/df /home|tail -n 1|awk '{print $5}'|cut -d% -f1) -lt "90" ] ; then echo "All is well"; else echo "Attention! Disk space" ; fi
 
Old 05-20-2009, 06:30 AM   #4
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
I need the script which can mail me if mount point filled more than 90 % . In our case we are having more than one mount point.

[oracle@nalinodb02 tmp]$ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/cciss/c0d0p8 1032088 738032 241628 76% /
/dev/cciss/c0d0p1 261868 36416 225452 14% /boot/efi
none 6229600 0 6229600 0% /dev/shm
/dev/cciss/c0d0p6 2064208 1279144 680208 66% /home
/dev/cciss/c0d0p5 10321208 781084 9015836 8% /opt
/dev/cciss/c0d0p7 2064208 272464 1686888 14% /tmp
/dev/cciss/c0d0p3 10321208 2785308 7011612 29% /usr
/dev/cciss/c0d0p4 10321208 389488 9407432 4% /var
/dev/mapper/oracle00_nalinodb02-lvol0
8692184 6566760 1683876 80% /oracle
/dev/mapper/dwtest01_clarion-lvol1
144443134 122455237 14648685 90% /dwtest01
/dev/mapper/dwtest02_clarion-lvol1
144443134 123577693 13526229 91% /dwtest02
/dev/mapper/dwtest03_clarion-lvol1
144443134 127231740 9872182 93% /dwtest03
/dev/mapper/dwtest04_clarion-lvol1
144443134 125118663 11985259 92% /dwtest04
/dev/mapper/dwtest05_clarion-lvol1
144443134 130373444 6730478 96% /dwtest05
/dev/mapper/dwtest06_clarion-lvol1
144443134 131143390 5960532 96% /dwtest06
/dev/mapper/dwdev01_clarion-lvol1
144443134 49041368 88062554 36% /dwdev01
/dev/mapper/dwdev02_clarion-lvol1
144443134 99779963 37323959 73% /dwdev02
/dev/mapper/dwdev03_clarion-lvol1
144443134 114374040 22729882 84% /dwdev03
/dev/mapper/dwdev04_clarion-lvol1
144443134 136234215 869707 100% /dwdev04
/dev/mapper/dwdev05_clarion-lvol1
144443134 18616758 118487164 14% /dwdev05
/dev/mapper/dwdev06_clarion-lvol1
144443134 4125719 132978203 4% /dwdev06
/dev/mapper/dwtest--np01-lvol1
10310682 12080 9774724 1% /dwtest/np01
marlins:/intfdata 282787840 176314496 99819520 64% /intfdata
/dev/mapper/mnudvlp_clarion-lvol1
288885169 156145008 118061736 57% /mnudvlp
/dev/mapper/mnutest_clarion-lvol1
288885169 130011725 144195019 48% /mnutest
/dev/mapper/owbtest_clarion-owbtest
41266479 10912729 28257008 28% /owbtest
/dev/mapper/owbtest_clarion-cogtest
41274541 4423824 34753565 12% /cogtest
/dev/mapper/owbdev_clarion-owbdev
41266479 8166337 31003400 21% /owbdev
/dev/mapper/owbdev_clarion-edidev
41274541 6257027 32920362 16% /edidev
/dev/mapper/oracledb_clarion-editest
41274541 6067005 33110384 16% /editest
/dev/mapper/oracledb_clarion-oracledb
41270445 4114280 35059218 11% /oracle1/db
/dev/mapper/dwtest07_clarion-lvol1
144443134 13616 137090306 1% /dwtest07
nalinnfs01:/stage 433442592 361421824 50006560 88% /stage
/dev/mapper/hrtest_clarion-hrtestdb
41258417 3070027 36092058 8% /hrtest/db
/dev/mapper/hrtest_clarion-hrtest
41274541 2396958 36780431 7% /hrtest01


-Thanks,
Jayraj
 
Old 05-22-2009, 07:54 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
You're using the wrong operator: http://www.tldp.org/LDP/abs/html/refcards.html#AEN21463
 
Old 05-22-2009, 10:37 AM   #6
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
maybe this will help maybe it won't

Code:
#!/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 10:56 AM.
 
Old 05-25-2009, 01:45 AM   #7
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
Thanks Fluid for the script. I will try your suggestion.

Last edited by jayraj005; 05-25-2009 at 01:49 AM.
 
Old 05-26-2009, 05:49 AM   #8
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
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

Thanks,
Jayraj
 
Old 05-26-2009, 05:54 AM   #9
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
df -kh|grep -v cciss|grep -v intfdata|grep -v Available|grep -v none|grep -v stage|awk '{print $4,$5}'|sed -e 's/%//g' -e '1,2d'
80 /oracle

90 /dwtest01

91 /dwtest02

93 /dwtest03

92 /dwtest04

96 /dwtest05

96 /dwtest06

36 /dwdev01

73 /dwdev02

84 /dwdev03

100 /dwdev04

14 /dwdev05

4 /dwdev06

1 /dwtest/np01

57 /mnudvlp

48 /mnutest

81 /owbtest

12 /cogtest

21 /owbdev

16 /edidev

16 /editest

11 /oracle1/db

1 /dwtest07

8 /hrtest/db

7 /hrtest01


From the above output. I need the script which atleast alert when the mount point filled 90%
 
Old 05-26-2009, 10:20 AM   #10
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Maybe it's what I'm evaluating the wrong item

what does this return?

df -h | grep -v capaci | awk '{print $5}' | cut -d% -f1

Should be the disk percentages minus the % sign (working on a Solaris server so it may display different).
 
Old 05-26-2009, 11:32 PM   #11
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 658

Rep: Reputation: 160Reputation: 160
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.

df -t | awk '{ .. }' | sendmail <mymailid>

End
 
Old 05-27-2009, 12:31 AM   #12
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
Output for following command
$ df -h | grep -v capaci | awk '{print $5}' | cut -d% -f1


Use
76
14
0
66
8
14
29
4

/oracle

/dwtest01

/dwtest02

/dwtest03

/dwtest04

/dwtest05

/dwtest06

/dwdev01

/dwdev02

/dwdev03

/dwdev04

/dwdev05

/dwdev06

/dwtest/np01
65

/mnudvlp

/mnutest

/owbtest

/cogtest

/owbdev

/edidev

/editest

/oracle1/db

/dwtest07
89

/hrtest/db

/hrtest01
$
 
Old 05-27-2009, 11:51 AM   #13
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
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

df -kh|grep -v cciss|grep -v intfdata|grep -v Available|grep -v none|grep -v stage|awk '{print $4,$5}'|sed -e 's/%//g' -e '1,2d'

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
 
Old 05-29-2009, 09:11 AM   #14
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
Thanks lot. It is working fine.
 
Old 05-29-2009, 09:14 AM   #15
jayraj005
LQ Newbie
 
Registered: May 2009
Posts: 0

Original Poster
Rep: Reputation: 0
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

Last edited by jayraj005; 05-29-2009 at 09:34 AM.
 
  


Reply

Tags
alert, mount, point


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
puppy+grub saves ram installed mount point as HD install mount point agualust Linux - Newbie 0 04-10-2009 12:23 PM
Increase space for mount point . . . eng_mohammedmostafa Linux - Software 7 03-26-2009 01:12 AM
Need more space to a mount point salmjuh Linux - Software 0 10-18-2004 06:03 AM
I need to reallocate drive space from mount point / to /boot decampbell1 Linux - Newbie 7 01-08-2004 03:34 PM


All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration