Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute command through while loop 1

Status
Not open for further replies.

UsRb

IS-IT--Management
Mar 19, 2007
48
HR
Hi,

I have following code:

while read f;
do ssh mbu-ibm-hmc1 lssyscfg -r lpar -m Server-9117-MMA-SN655D340 -F name,state --filter lpar_names=$f;
done < 1

1 is a file containing lpar names:
mbu-test-uat-cms-dbms-01
mbu-pci-euroit-dbms-03
mbu-pci-euroit-dbms-02
mbu-pci-test-dbms-01
mbu-pci-euroit-dbms-01
mbu-pci-cms-test-dbms-01
mbu-dev-dbms-01
mbu-prod-cms-app-01
mbu-prod-cms-dbms-01
mbu-prod-pte-dbms-01
mbu-vios-01-02
mbu-vios-01-01

The code should execute one command for one line in file 1 containing lpar_names.
When I execute the code, output is only for the first line in file 1. Why does it stops, where is the catch?
 
This one had me stumped for ages when I came across it. The answer is that the ssh command reads stdin and effectively 'eats' the input file. Replace with
Code:
while read f;
do ssh [COLOR=#ff0000][b]-n[/b][/color] mbu-ibm-hmc1 lssyscfg -r lpar -m Server-9117-MMA-SN655D340 -F name,state --filter lpar_names=$f;
done < 1


On the internet no one knows you're a dog

Columb Healy
 
Already answered here:
thread822-1277615

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you guys a million!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top