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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a list to do repetitive work 1

Status
Not open for further replies.

willster

IS-IT--Management
Aug 6, 2004
12
US
I have a command that I want to run against a large number of servers. I have the list of servers, how do I run it against one server at a time? Any help would be appreciated.
 

Try:
Code:
for lin in `cat server.lst`
do
  echo "Procesing server: $lin"
done
#-- Or --
While read var
do 
  echo "Procesing server: $var"
done <server.lst
[:eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thanks for the quick responce. That seems to do the trick.
 
LKBrwnDBA said:
for lin in `cat server.lst`
do
echo "Procesing server: $lin"
done

#-- Or --

while read var
do
echo "Procesing server: $var"
done <server.lst

When running a rsh/ssh loop, I prefer to use the "for ... in" construction. On some 'nixes, the rsh or ssh command eats away at the stdin, and the "while read var" statement is only able to read the first line of its input and hits an EOF after the first rsh or ssh terminates.
Another solution is to provide an empty stdin for the rsh or ssh command line.

so:

for variant:
for svr in `cat $LIST`
do
rsh $svr /what/ever/command
done

while variant:
while read svr
do
rsh $svr /what/ever/command </dev/null
done < $LIST



HTH,

p5wizard
 
Or use the -n option to rsh/[b/]ssh[/b], which I think does pretty much the same thing.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top