1752777 Members
6016 Online
108789 Solutions
New Discussion юеВ

help with "for loop"

 
SOLVED
Go to solution
Mike_305
Super Advisor

help with "for loop"

Hello,

I am trying to run lanadmin and fc command from on mgmt server to several server using ssh.

I am using "for loop" to do this but not worknig. Appreciate any help.

for Y in $(cat sr.lst)

do

ssh -n $Y CMD=$(lanscan | awk '{print $3}' | grep -v Crd | grep -v In#) 2>/dev/null

ssh -n $Y "echo $CMD > a.lst" 2>/dev/null

for X in $(< a.lst)

do

ssh -n $Y lanadmin -g $X | grep -i status 2>/dev/null

done

done


Regards,

MP
If there is problem then don't think as problem, think as opportunity.
3 REPLIES 3
ankitj1983
Frequent Advisor
Solution

Re: help with "for loop"

Hello,

You can follow the below looping.

while read inputline

do

ssh -n $Y CMD=$(lanscan | awk '{print $3}' | grep -v Crd | grep -v In#) 2>/dev/null

ssh -n $Y "echo $CMD > a.lst" 2>/dev/null

done
while read inputline
do

ssh -n $Y lanadmin -g $X | grep -i status 2>/dev/null

done
Let me know if you find any difficulty.

Regards

Ankit


Laurent Menase
Honored Contributor

Re: help with "for loop"

for Y in $(cat sr.lst)
do
A=$(ssh -n $Y "lanscan | \
awk '/In#/||/Crd/{continue}{print \$3}'"\
) 2>/dev/null

for X in $A
do
echo $Y:$X
ssh -n $Y "yes|lanadmin -g $X" | grep -i \
status 2>/dev/null
done
done
Mike_305
Super Advisor

Re: help with "for loop"

Sorry for the late point. My Apologies.

Regards,

MJ
If there is problem then don't think as problem, think as opportunity.