joaotelles
asked on
Shell script - run command using variable from a list
Hi,
I need to issue a command to 10 hosts remotely and I was wondering what would be the best way to script it so I wouldnt have run it over and over for each one of them...
I was thinking on having a host list variable in a script and use:
ssh $HOST <command>
For each command I run I need to create a output file in the local machine where Im issuing the command from...
So it would be: ssh $HOST1 <command> > HOST1, ssh $HOST2 <command> > HOST2.. and so on....
What would be the best way to do it in a shell script?
Tks
I need to issue a command to 10 hosts remotely and I was wondering what would be the best way to script it so I wouldnt have run it over and over for each one of them...
I was thinking on having a host list variable in a script and use:
ssh $HOST <command>
For each command I run I need to create a output file in the local machine where Im issuing the command from...
So it would be: ssh $HOST1 <command> > HOST1, ssh $HOST2 <command> > HOST2.. and so on....
What would be the best way to do it in a shell script?
Tks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
for HOST in $(<hostlist)
do
ssh $HOST <command> > ${HOST}.result
done