Link to home
Start Free TrialLog in
Avatar of a3global
a3global

asked on

Streamline a For loop in Ksh

I wrote a for loop script in KSH which is working absolutely file, The code is below

###############################################################
echo " Output of the current SEA's Setup " 
ssh -n -x -2 $VIOA "lsdev -Cc adapter" | grep -i shared | awk '{print $1}' > $VIOA.seas
ssh -n -x -2 $VIOB "lsdev -Cc adapter" | grep -i shared | awk '{print $1}' > $VIOB.seas

for i in $VIOA $VIOB
 do
echo "$i"
   for j in `cat $i.seas`
          do
          a=`ssh -n -x -2 $i  "entstat -d $j" | egrep -i "primary|backup"| grep State`
          b=`ssh -n -x -2 $i "entstat -d $j" | egrep -i "VLAN Tag IDs" | grep -v None`
          echo "$j($b)    $a"
          done
done

For your reference
# cat $VIOA.seas
ent33
ent34
ent35

The output is something like...
sysvio118a




ent33(VLAN Tag IDs:  3166)        State: PRIMARY




ent35(VLAN Tag IDs:   183   199   215   909   916   919)        State: PRIMARY




ent36(VLAN Tag IDs:  2036  3052)        State: PRIMARY
sysvio118b




ent33(VLAN Tag IDs:  3166)        State: BACKUP




ent35(VLAN Tag IDs:   183   199   215   909   916   919)        State: BACKUP




ent36(VLAN Tag IDs:  2036  3052)        State: BACKUP

Open in new window


How do I efficiently write this code so that I dont get the empty lines, If we can do this in While, How can we do this..

Thanks
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of a3global
a3global

ASKER

Lot Lot Cleaner.....Thanks...
Just for completeness - here's the "while" loop.
Please note that using "while" or "for" has no influence on those empty lines,
and please note, too, that the "-n" flag of "ssh" is mandatory with "while read ..." but not necessarily with " for ... in ..."

while read j
          do
          a=`ssh -n -x -2 $i  "entstat -d $j" 2>/dev/null | egrep -i "primary|backup"| grep State`
          b=`ssh -n -x -2 $i "entstat -d $j" 2>/dev/null | egrep -i "VLAN Tag IDs" | grep -v None`
          ### OR
          ### a=`ssh -n -x -2 $i  "entstat -d $j" 2>&1 | egrep -i "primary|backup"| grep State`
          ### b=`ssh -n -x -2 $i "entstat -d $j" 2>&1 | egrep -i "VLAN Tag IDs" | grep -v None`
          echo "$j($b)    $a"
          done < $i.seas

Thx for the points!