Tuesday, December 17, 2013

KSH Script to Compare to Numeric Values

www.unixbabuforum.inI have to write a script that compare two numeric values V1 and V2 etc ... 
For instance : 
if [ X1 -gt X2 ]; then 
echo X1 is greater then X2 etc ... 

My problem is how to turn those two values as numeric , because : 
V1 is the value of the estimate size of an mksysb 
V2 is the available space on file system on where to create the mksysb 
And the purpose is to estimate the size of the mksysb before creating it or not. 

The command to estimate the mksysb file is (it works fine) : 
df -tk `lsvgfs rootvg` | awk '{total+=$3} END {printf "Mksysb size is : %.2f GB\n", total/1024/1024}' 

The command to estimate the available space to put the mksysb , here in /tmp, also works fine : 
df -g '/tmp' | grep -vi free | awk '{espace_dispo=$3} END {printf "Avalable space in /tmp for mksysb is : %.2f GB \n", espace_dispo}' 

Now I need to put the two values in numeric variable to compare them and start an mksysb or not. 

www.unixbabuforum.inTry this:
esti=`df -tk \`lsvgfs rootvg\` | awk '{total+=$3} END {printf "%.2f\n", total/1024/1024}'` 
dfest=`df -g '/tmp' | grep -vi free | awk '{espace_dispo=$3} END {printf " %.2f \n", espace_dispo}'` 
if [ "${esti}" -gt "${dfest}" ] 
echo "Estimated mksysb size is greater, please increase the /tmp size and re-run" 
mksysb -ie /tmp/mksysb_`hostname`_`date +%d%h20%y%H%M` 


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM