Require Help for Shell Script

Hi friends,

i am trying to print warning for partition size which exceed limit of 90%
& other are ok.

i m using below command which print partition which exceed 90%

# df -h | sort -k5 | head -1 | awk 'END{ print $1" :- Not Having more space on This Partition"}'

i want to print other partition which is below 90% with warning like " This partition having enough space"

Please Help

Thanks & regards
Jag Nikam

Try this:

df -k | awk '{if($5~/9[0-9]%/)print $NF" is out of space"; else print $NF" has enough space"}'

You may want to run the df command with '-F ufs' or '-F vxfs' as well so that you don't get alerts for swap, fd and such.

thanks
but it will print "has enough space " for all partition

:confused:
Ok no one replying for this command so finally i started 2 write script now i m facing same problem

#!/bin/bash
Warning=90
df -h | sort -rn | awk '{print $5 " " $1 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if $usep -ge $Warning ; then
echo "Running out of space \"$partition ($usep%)\""
else
echo "This partition have enough space \"$partition ($usep%)\""
fi
done

Please Help Me

good for you. however, by simply searching on the forum, you can find a few posts similar to yours.

Dear jagnikam,

ur code fine, but take care about the syntax of scripting
i have just corrected ur basic faults...

try it out

#!/bin/bash
Warning=90
df -h | sort -rn | awk '{print $5 " " $1 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $Warning ]
then
echo "Running out of space \"$partition ($usep%)\""
else
echo "This partition have enough space \"$partition ($usep%)\""
fi
done

and my one more suggestion is redirect the output if df -k in a file and the remove the first line of the file and then proceed...
ur current code is proceeding with the first line also which u dont need.

Regards,
Pankaj

thanks for reply
I got this output after executing script provided by U. actually i am using NFS & some drive mounted on my HDD. this creating problem for me .

This partition have enough space "192.168.0.2:/usr (38%)"
./test1.sh: line 7: [: 192.168.0.2:/tftpboot/nodes/192.168.0.106/var: integer expression expected
This partition have enough space " (192.168.0.2:/tftpboot/nodes/192.168.0.106/var%)"
./test1.sh: line 7: [: 192.168.0.2:/tftpboot/nodes/192.168.0.106/etc: integer expression expected
This partition have enough space " (192.168.0.2:/tftpboot/nodes/192.168.0.106/etc%)"
./test1.sh: line 7: [: 192.168.0.2:/tftpboot/node_root: integer expression expected
This partition have enough space " (192.168.0.2:/tftpboot/node_root%)"
./test1.sh: line 7: [: 192.168.0.15:/var/spool/mail: integer expression expected
This partition have enough space " (192.168.0.15:/var/spool/mail%)"
./test1.sh: line 7: [: 192.168.0.15:/tftpboot/node_root/var/lib/dpkg: integer expression expected
This partition have enough space " (192.168.0.15:/tftpboot/node_root/var/lib/dpkg%)"
./test1.sh: line 7: [: 192.168.0.15:/neuralit/work: integer expression expected
This partition have enough space " (192.168.0.15:/neuralit/work%)"
./test1.sh: line 7: [: /home: integer expression expected
This partition have enough space "110G (/home%)"
./test1.sh: line 7: [: /var/lib/dpkg: integer expression expected
This partition have enough space "65G (/var/lib/dpkg%)"
./test1.sh: line 7: [: /var: integer expression expected
This partition have enough space "65G (/var%)"
./test1.sh: line 7: [: /etc: integer expression expected
This partition have enough space "65G (/etc%)"
./test1.sh: line 7: [: /: integer expression expected
This partition have enough space "65G (/%)"
./test1.sh: line 7: [: /var/spool/mail: integer expression expected
This partition have enough space "6.0G (/var/spool/mail%)"
This partition have enough space "varrun (1%)"
This partition have enough space "varlock (1%)"
This partition have enough space "tmpfs (1%)"
This partition have enough space "tmpfs (0%)"
This partition have enough space "tmpfs (0%)"
This partition have enough space "none (1%)"
./test1.sh: line 7: [: Use: integer expression expected
This partition have enough space "Filesystem (Use%)"
This partition have enough space "devshm (0%)"

Please Help me

Tanks & Regards

Jagannath Nikam

Dear jagnikam,

./test1.sh: line 7: [: /var/spool/mail: integer expression expected
This error mean values of $usep variable is null...

debug it using sh -x <scriptname.sh>
and check why the value of /var/spool/mail is cuming null.

u'll be able to kno the error

Regards,
Pankaj

Thanks Pankaj :b:

Hi finally i used this script but i can not remove blank lines from output then while it compare with 90 it gives me error like " expr: syntax error "
this is just because of BLANK LINES

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

#!/bin/bash
df -h | while read name
do
aa=$(echo $name | grep -v 172.16.0.15:/var/spool/mail | grep -v 172.16.0.15:/tftpboot/node_root/var/lib/dpkg | grep -v 172.16.0.15:/neuralit/work | grep -v 172.16.0.2:/tftpboot/node_root | grep -v 172.16.0.2:/tftpboot/nodes/172.16.0.112/etc | grep -v 172.16.0.2:/tftpboot/nodes/172.16.0.112/var | grep -v Filesystem | grep % | grep -v ^$ )
echo $aa

for i in $aa ; do
if [ "$i" == " " ]; then
echo "empty"
fi
done

bb=$(echo $aa | awk '{print $4 }' )

echo $bb

cc=$(expr substr $bb 1 2 )

echo $cc

if test $cc -gt 90
then
echo " size greater than 90%"
fi

done

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

please help me

Thanks & Regards
Jagannath Nikam

Can anybody overthere who look on above script ..................>>>?

Please be aware this is a Free Forum, people here help because they want to. Using bold large red caps and demanding service, is going to get you ignored real quick! Even if you was paying people, that's not going to get you very far.

My systems don't have a 'df -h' option, so I tested this wtih 'bdf -l" for HP-UX and "df -lk" for Solaris, so you'll need to substitute your 'df -h'.

I'm printing "disk", "percentage" and the "full or has space message"

## Disk full
bdf -l | awk '$5~/100|9[0-9]/{print $1,$5,"Disk Full" }'

## Disk has space
bdf -l |  awk '$5~/[0-8][0-9]/{ if ($5 != "100%") print $1,$5,"Disk has space" }'

so you should be able to use the following:

## Disk full
df -h | awk '$5~/100|9[0-9]/{print $0,$5,"Disk Full" }'

## Disk has space
df -h |  awk '$5~/[0-8][0-9]/{ if ($5 != "100%") print $1,$5,"Disk has space" }'

Thanks for reply

Both are not working for me I am using Ubuntu Servers. I had mounted some network partition on that System thats why it shows wrong output

Please help me 2 solve this problem
Thanks & regards

df -k |tail -n +2| awk '{if($4~/100|9[0-9]%/)print $NF" is out or running out of space ****"; else print $NF" has enough space"}'

if this doesn't work for you can you send a df -k output from your system:b:

Hi sjday

Thanks a lot :b:
My problem is solved

Thanks & regards
Jagannath Nikam