Filter output as an array element

I am filtering the value of Server status from a file and am storing it in a temp file which I compare later to exit with appropriate status. I am wondering if I can directly output the value of Server status as an array element and then compare the value of elements to get the right exit status

#!/bin/csh -f
cat srvoff | /usr/bin/grep -i 'Tx Server Status' | /usr/bin/awk '{print $4}' > /tmp/status
cat srvoff | /usr/bin/grep -i 'Eg Server Status' | /usr/bin/awk '{print $4}' >> /tmp/status
cat srvoff | /usr/bin/grep -i 'ASM Server Status' | /usr/bin/awk '{print $4}' >> /tmp/status
cat srvoff | /usr/bin/grep -i 'Int server' | /usr/bin/awk '{print $3}' >> /tmp/status
cat srvoff | /usr/bin/grep -i 'DIPoller' | /usr/bin/awk '{print $4}' >> /tmp/status

set new = `cat /tmp/status`
set new = ( $new )
rm /tmp/status

if ( "$new[1]" =~ Active && "$new[2]" =~ Active && "$new[3]" =~ Active && "$new[4]" =~ Active && "$new[5]" =~ Active) then
    exit 110
else if (  "$new[1]" =~ NOT && "$new[2]" =~ NOT && "$new[3]" =~ NOT && "$new[4]" =~ NOT && "$new[5]" =~ NOT ) then
   exit 100
else
   exit 1

How about this:

#!/bin/csh -f
set new = ( `awk '/Tx Server Status|Eg Server Status|ASM Server Status|DIPoller/ {print $4} /Int server/ {print $3}' srvoff` )
 
if ( "$new[1]" =~ Active && "$new[2]" =~ Active && "$new[3]" =~ Active && "$new[4]" =~ Active && "$new[5]" =~ Active) then
exit 110
else if ( "$new[1]" =~ NOT && "$new[2]" =~ NOT && "$new[3]" =~ NOT && "$new[4]" =~ NOT && "$new[5]" =~ NOT ) then
exit 100
else
exit 1
endif
1 Like

wow that did the trick. Thanks