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

Running a set of commands on different servers

Status
Not open for further replies.

gvidos

Programmer
Jul 24, 2002
17
0
0
GR
Hi,

This is the first time I need to write a script, so I desparately need your help folks!

Well, I need to run a set of commands in a set of servers. That is:

I need to run:

{
command 1
command 2
command 3
}
on all servers:
{
server 1
server 2
.....
server 6
}

and then after 10 secs
run
command 4 concurrently on all 6 servers

in order to get statistics of the execution of command 3

I've seen something about 'rsh' command in Unix but it accepts only one command as argument at a time.This means that I'll have to use 3 times the rsh command for every server and that will happen 6 times (6 servers).

Is there any chance of actually executing command 4 concurrently at all 6 servers (or at least with little latency)?

thanks,

George
 
rsh will accept more than one command in the form rsh servername "command1;command2;command3"

Greg.
 
Maybe I didn't express what I wanted clearly,or maybe you didn't get question right.

The most hot issue is how I can run concurrently (starting at the same time) 6 rsh commands.
Also,the first command,waits for stdin (it never finishes,occupying the terminal).
Also how do I start command 4 at the same time on all 6 servers?
if I got the hostnames of the six servers,can I assign them in a variable,eg:

SERV="dilos kos milos samos limnos ios"

and then

cur_time=system(time) /* like what we would do in C */

for i in SERV
rsh command 1 $i
rsh command 2 $i
rsh command 3 $i
rsh "at cur_time+10sec command 4" $i
done

what I just wrote is not actual in script writing but as pseudo-code.

Please help,

I am in need of a decent answer.
 
It's *doable* but not quite exactly as you specify.

If the major concern is to major sure everything happens at exactly the same time, I'd do everything via atjobs and make sure all times across all machines are synced.

r commands also have this little behavior of messing up loop processing (at least in ksh), so when I have to do something like that, I have my script create another script and run that.

Finally, since the overall process is easily scriptable, push a script out and run that:

[tt]work_to_do.sh[/tt]
#!/bin/ksh

echo "process1" | at now # this fires off process one detached from any interactive terminal
process2
process3
sleep 10
process4
#rm ${0} # make this script suicide if you want[/tt]

[tt]main.sh[/tt]
#!/bin/ksh

ATTIME=now + 100 years
RUNME=/tmp/$$
SERVERLIST=/serverlist

rm ${RUNME} 2>/dev/null

cat ${SERVERLIST} | while read SERVER
do
echo "rcp work_do_to.sh ${SERVER}:work_to_do.sh" >> ${RUNME}
echo "rsh ${SERVER} \"echo work_to_do.sh | at ${ATTIME}\"" >> ${RUNME}
done

ksh ${RUNME}

rm ${RUNME} 2>/dev/null[/tt]

That's a fairly rough implementation. It may require some debugging.
 
Yes, that sounds straight enough, but what if the system hasn't got ksh?
Also,there is a problem with rsh,it hangs waiting for I don't know what,when I issue the command:

rsh server command

There is also one problem:

the processes 1,..,4 have a filename that goes after:

"gen_" + server
"dsconf_" + server
"stopq_" + server

Is it possible to make it so much parameterized?

I mean how can you concatenate the previous strings with the server's name in order to get the appropriate filename?

thanks for your help Chapter11

p.s. how can I get the parameter time+10min?

I've found that I can get the ccurrent time from:

date +%H%M

but how can I add 10 mins to that?


cheers
 
1) If the systems involved don't have ksh, use another shell. Plain sh might work; it's just a matter of syntax at that point.

2) If rsh isn't working, you'll have to figure that out separately.

3) If the processes listed in what I wrote as "work_to_do.sh" run their commands with the machine's local hostname, you can do this:

[tt]process1 `hostname`
process2 `hostname`[/tt]
and so on.

4) If you have gnu's version of "date", you can do this: "date --d now + 10 minutes". A proprietary version of "date" probably won't let you do that.

I spend all of my time in ksh, so that's the syntax I know. Perhaps someone else can translate my syntax into a shell you have available.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top