Solved Run AWK from within a korn shell

December 19, 2011 at 08:50:30
Specs: AIX 5.3, 4 CPU / 32 GB RAM
Hello all,

Could someone please assist? I have an AWK routine the successfully prints a warning message for filesystem usage equal/greater than 90% when called as:
df -k | awk -f script.awk

I would like to call the entire routine from within a KORN shell script. I can't seen to get it to work, please see below:

df -k | awk '{

{
if($1=="Filesystem")
next
}

{
for(i=1;i<=NF;i++)
if($i ~/%/)
FLD=i

if($FLD !~/-/)
usage=sprintf("%d\n", substr($FLD,1,index($FLD,"%")-1)+0)

if(usage>=90)
printf("%s;%s%s%d%s\n", "Filesystem warning",$NF," usage at ",usage,"%")
}

}'

What am I not doing currently?


See More: Run AWK from within a korn shell

Report •


#1
December 19, 2011 at 09:44:10
✔ Best Answer
I rearranged the curly braces and changed the way the % sign was eliminated:

#!/bin/ksh

df -k | awk '{

if($1=="Filesystem")
   next

for(i=1; i<=NF; i++)
   if($i ~ /%/)
      FLD=i

#   if($FLD !~ /-/)
#      usage=sprintf("%d\n", substr($FLD,1,index($FLD,"%")-1)+0)
   gsub("%","",$FLD)
   usage=$FLD + 0

   if(usage>=90)
      printf("%s;%s%s%d%s\n", "Filesystem warning",$NF," usage at ",usage,"%")
}'


Report •

#2
December 20, 2011 at 08:11:11
Many thanks for your help nails.

Report •
Related Solutions


Ask Question