Q:

HP-Unix: C-shell:Disk space checking

I have 10 devices that using hp-ux and i want to check the disk space in each devices.
my requirement is if the space more than 90%, the info of device ans space will be save to a log.
this is list of device and ip address which i set as variable ipadd:
lo1 100.45.32.43
lot2 100.45.32.44
lot3 100.45.32.44
lot4 100.45.32.45
lot5 100.45.32.46 
and so on..

This is my script so far :
#!/bin/csh -f

set ipaddress = (`awk '{print $2}' "ipadd"`)
set device = (`awk '{print $1}' "ipadd"`)

@ j = 1
while ($j <= $#ipaddress)
   echo $ipaddress
   set i = 90        # Threshold set at 90%
   set max = 100
   while ($i <= $max)         
      rsh $ipaddress[$j] bdf | grep /dev/vg00 | grep $i% \
      |awk '{   file=substr($6,index($6,"/") + 1,length($6)); print "WARNING: $device[$j]:/" file " has reached " $5 ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space." file ".file"}'    
      @ i++
   end
   @ j++
end

The output after bdf:
/dev/vg00/lvol2    15300207 10924582 28566314   79% /
/dev/vg00/lvol4      42529   23786   25510   55% /stand

The output at terminal after exec the script:
100.45.32.43
100.45.32.44

The output at .file:
WARNING: $device[$j]:/ has reached 79%. Perform HouseKeeping   IMMEDIATELY...

My question is, is it my looping have something wrong cause only iterates one time only because my .file output only show one device only?
And why $device[$j] not come out in .file output?
or awk have problem?
Thank you for the advice.

A:

Your code tested for each possible percentage between 90 and 100. 
Persumably, you'd be OK with code that checks once, and asks 'is device percent greater than 90%'?. So then you don't need the inner loop at all, and you make only 1 connection per machine, try
#!/bin/csh -f

set ipaddress = (`awk '{print $2}' "ipadd"`)
set device = (`awk '{print $1}' "ipadd"`)
@ j = 1
set i = 90        # Threshold set at 90%
while ($j <= $#ipaddress)
   echo $ipaddress
   echo "#dbg: ipaddress[$j]=${ibpaddress[$j]}"
   rsh $ipaddress[$j] bdf \
   | awk -v thresh="$i" -v dev="$device[$j]" \
      '/\/dev\/vg00/ { \
          sub(/%/,"",$5) \
          if ($5 > thresh) { \
           file=substr($6,index($6,"/") + 1,length($6)) \
           print "WARNING: " dev ":/" file " has reached " $5 ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space." file ".file" \
       }\
     }'    
   @ j++
end

Sorry, but I don't have a csh available to dbl-chk for syntax errors.
So here is a one liner that we determined worked in your environment.
rsh $ipaddress[$j] bdf | nawk -v thresh="$i" -v dev="$device[$j]" '/\/dev\/vg00/ { sub(/%/,"",$5) ; if ($5 > thresh) { file=substr($6,index($6,"/") + 1,length($6));print "#dbg:file="file; print "WARNING: " dev ":/" file " has reached " $5 ". Perform HouseKeeping IMMEDIATELY..." >> "/scripts/space.file.TMP" } }'

I don't have a system with bdf available. Change the two references to $5 in the sub() and if test to match the field-number of the output that has the percentage you want to test.
Note that -v var="value" is the standard way to pass a variable value from the shell to an awk script that is enclosed in single-quotes. 
Be careful that any '\' chars at the end of a line are the last chars, no trailing space or tabs, or you'll get an indecipherable error msg. ;-)
IHTH

