Hi All,
My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert:
#!/bin/bash
export DBALIST="abc@xyz.com"
df -k /oradata/xyz/archive > dfk.result
archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4`
if [[ $archive_capacity > 60% ]]
then
mailx -s "Filesystem /oradata is ${archive_capacity} filled" $DBALIST < dfk.result
fi
Existing output in the subject mail alert is:
"Filesystem /oradata is Use% filled"
Expected output in the subject mail alert should be:
"Filesystem /oradata is 61% filled"
Anyone could please suggest what's wrong here!
Thanks for your time!
Regards,
Change the line above to:
archive_capacity=`grep -v File dfk.result | awk -F" " '{ print $5 }' | cut -c 1-4`
HTH
RTM
May 7, 2010, 2:07pm
3
If your 'df -k' command has this header, then when you search for %, it picks out the first one.
Filesystem 1K-blocks Used Available Use% Mounted on
archive_capacity=`awk -F" " '{ print $5 }' /tmp/dfk.result`
echo $archive_capacity
archive_capacity=`echo $archive_capacity|grep -i %| cut -c 1-4`
echo $archive_capacity
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 244124256 16086488 228037768 7% /var/local
Use% 7%
Use%
Changing your cut command to this will give you the number (may have to play with this a bit)
archive_capacity=`awk -F" " '{ print $5 }' dfk.result`
echo $archive_capacity
archive_capacity=`echo $archive_capacity|grep -i %| cut -c 6-8`
echo $archive_capacity
Output:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 244124256 16086792 228037464 7% /var/local
Use% 7%
7%
better yet, skip that intermediate step of outputting to a file and then reading back in:
#!/bin/bash
export DBALIST="abc@xyz.com"
archive_readout=$(df -k /oradata/xyz/archive |egrep "^Filesystem|\%" )
archive_capacity=$(df -k /oradata/xyz/archive |awk '{ print $5 }' |grep -i % |sed 's/%//g' )
if [[ $archive_capacity > 60 ]]
then
print ${archive_readout} |mailx -s "Filesystem /oradata is ${archive_capacity}% filled" $DBALIST
fi
RTM
May 7, 2010, 5:03pm
5
interesting - since I didn't have /oradata/xyz/archive to test with, I changed it to either /var or /home. My /home is at 5% - yet the script still sent an email - the ORIGINAL script has other issues... would have mention this earlier but email was real slow!
Curleb - your changes work as far as getting the numbers right - for some reason I got errors on the print/mailx line (on Linux) - no big deal
Hmmm...works for me on Solaris10, ksh.
...with local filesystems too, of course...