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.
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%)"
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
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" }'