#!/bin/ksh for AIX
used=0
mount=${1:-"/mountpoint"}
threshold=${2:-80}
#message="hello"
#SUBJECT="Disk Space Alert"
#EMAIL="xyz@abcinc.com"
used=`df -k $mount | grep % | awk '{print $5}' | sed 's/%//g'`
#echo "Free Space available under \"$mount\" is `expr 100 - $used`%.\n">$message
if [ $used -ge $threshold ]; # at this point am getting error#
then
echo "Space Utilization on \"$mount\" has exceeded the threshhold of ${threshold}%.\n" | mail -s "Disk Space Alert" xyz@abcinc.com
#/bin/mail -s "$SUBJECT" "$EMAIL" < $message
fi
*at if operator it gives "./disk.sh[14]: 180533: unknown test operator" error
can any one help guys ,thanks in advance.
Without seeing a sample "df -k", I think that the problem is because the column headings include a "%" character. Suggest you have a custom "grep -v" early in the pipeline to get rid of the column headings line.
echo $used and see what is the value you are getting first.
Test should work indeed ok in AIX as well.
Also, check which ksh and use that if it's not /bin/ksh
In fact, please post a sample "df -k" of a filesystem.
On my non-AIX system I'd have to use "df -k -P" to get a line-across format where $5 was the percentage free space.
The problem is that you are not eliminating the heading printed by the df command.
Execution yields:
df -k /home | grep % | awk '{print $5}' | sed 's/%//g'
Use
1
Change:
df -k /home | grep % | awk '{print $5}' | sed 's/%//g'
to
df -k /home | grep % | awk '{print $5}' | sed 's/%//g | tail -1'
and you should be fine.
On top of the header line being processed as mentioned by Blytsplyk, it looks like you want %Used which is field 4 and not field 5, which is Iused!
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
So I'm guessing the following might work better:
used=`df -k $mount | tail -1 | awk '{print $4}' | sed 's/%//g'`
Are you looking for something like this:
>mi_df
============================================================================================================
Filesystem Size (MB) Free (MB) %Used %Iused Mount
============================================================================================================
/proc 0 0 - - /proc
/ 512 382 26 13 Root
/I 16384 7380 55 2 /dev/I_lv
/data 222208 99457 56 1 /dev/data_lv
/downloads 49152 6064 88 4 /dev/download_lv
/home 8192 4695 43 7 /dev/hd1
/home/sybase 2048 768 63 5 /dev/sybase_lv
/ms_temp 4096 4064 1 1 /dev/ms_temp_lv
/nim_export 65536 8133 88 4 /dev/nim_lv
/opt 2048 817 61 13 /dev/hd10opt
/tftpboot 128 75 41 1 /dev/fslv00
/tmp 256 246 4 1 /dev/hd3
/usr 5120 2544 51 11 /dev/hd2
/var 1024 302 71 18 /dev/hd9var
============================================================================================================