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

Help with While loop

Status
Not open for further replies.

blx

MIS
Oct 9, 2002
23
GB
Hi all,
I have a file containing a list of servers.
I want to start a service on each of these servers at 15 minute intervals - e.g. start service on server1, sleep for 15 minutes, start service on server2 sleep for 15 mins etc, until the whole list of servers has had the service started on them.
I'd be grateful if anyone could suggest the best way to do this in a while loop.

by the way, I'm doing this in bash

Thanks in Advance
blx

 
Well, the problem you will run into if you're trying to use rsh or ssh to remote-execute is that they both break stdin and make it impossible to actually use a while loop.

Not impossible, there's a trick to do some i/o redirection, but I prefer the simpler method of having a script write a sub-script and running that:

[tt]#!/bin/ksh

TF=/tmp/$$
CMDTOEXEC="uptime"
DELAY=900
# delay is measured in seconds
rm ${TF} 2>/dev/null

echo "#!/bin/ksh" >> ${TF}
echo "" >> ${TF}

cat ${SERVERLIST} | while read SERVER
do
echo "rsh ${SERVER} '${CMDTOEXEC}'" >> ${TF}
echo "sleep ${DELAY}" >> ${TF}
done

ksh ${TF}

rm ${TF} 2>/dev/null[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top