Operating System - Linux
1824975 Members
4463 Online
109678 Solutions
New Discussion юеВ

runnig shell script on many servers

 
SOLVED
Go to solution
Shivkumar
Super Advisor

runnig shell script on many servers

Dear Sirs,

I have a script available on one of the server. Is it possible to run it om many servers by executing on one server ?

Thanks,
Shiv
10 REPLIES 10
James R. Ferguson
Acclaimed Contributor
Solution

Re: runnig shell script on many servers

Hi Shiv:

That depends on what your shell script does. As long as it uses code that exists on the *other* servers, then "yes".

For example, if I wanted to collect the 'uname' information on a number of servers, I could do something like:

# for host in hostA hostB hostC
> do
> remsh -n 'uname -a'
> done

The key is that the 'uname' command is available on each host and is executed there.

If the server isn't setup for 'remsh' then you could substitute 'rexec'. See the manpages for 'remsh(1)' for more information.

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: runnig shell script on many servers

Hi Shiv, Yes, It is possible to run script on multiple servers, you can use remsh or any custom methods like, having a centralised server and it pushes scripts to agents which are running in other servers, this can be achieved by Java or C programs.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: runnig shell script on many servers

You can use remsh / rexec commands to execute.

or

ssh command to execute in remote machine

or

using expect script to give password and execute.

or using telnet + piping scripting as,

(
echo "root"
sleep 2
echo "passwd"
sleep 2
echo ""
sleep 2
echo "exit"
) | telnet hostname

-Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: runnig shell script on many servers

Hi Shiv, You can use "expect" utility as well to run automated remote execution.

http://expect.nist.gov/

http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.43/

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Kasper Hedensted
Trusted Contributor

Re: runnig shell script on many servers

Hi Shiv,

You could distribute and execute the script using SSH:

for HOST in A B C
do
scp myscript username@$HOST:/tmp/myscript
ssh $HOST /tmp/myscript
done

You might want to put in checks to make sure that the script is not executed if the transfer fails etc.

If you want to do this without entering passwords, you can setup "public-key authentication" - for more information take a look at this site: http://www.cvrti.utah.edu/~dustman/no-more-pw-ssh/

Regards,
Kasper
Arturo Galbiati
Esteemed Contributor

Re: runnig shell script on many servers

Hi Shiv,
if on the other server you have the same scripts and the same environment (same path, same aliases ans so on) the answer is yes.
I do teh same using remsh.
remeber to load the profile prior to execute your script on remote server.
man remsh for more info regarding the input/output redirection.
HTH,
Art
Ralph Grothe
Honored Contributor

Re: runnig shell script on many servers

This loop scrcipting is cumbersome and too time consuming if you need to run the same command on, say some hundred nodes.
The typical environment where this is necessary is usually number crunching clusters.
That's why those folks already devised a whole bunch of cluster maintenance solutions.

Here are some such

http://www.llnl.gov/linux/pdsh/pdsh.html

http://www.csm.ornl.gov/torc/C3/

http://sourceforge.net/projects/dcmd/

http://tentakel.biskalar.de/

http://ganglia.sourceforge.net/


Most of those can be built with SSH integration.
I personally find PDSH pretty neat and easy to set up.

Madness, thy name is system administration
Mark Ellzey
Valued Contributor

Re: runnig shell script on many servers

Shiv,

One other way to run a script on many servers is to put the script in a filesystem that is exported to all other systems. You can then run the script by mounting the filesystem on each of the NFS client machines.

For example, I have a backup script that I run nightly on a variety of servers. I installed the script on a Network Appliance partition called /backups. This partition is exported to all the servers at the site. Thus, I can put something like:

00 30 * * * /backups/backup.sh

in the crontab of each server. Of cource, you have to make sure that /backups is mounted on the various servers, or you cron job will fail.

Just another method...

Regards,
Mark
PeterWolfe
Respected Contributor

Re: runnig shell script on many servers

Shiv,

Ralph's reply above mentioned "pdsh" or Parallel Distributed
Shell. This open source tool included as part of the
Distributed Systems Administration Utility (DSAU) with
HP=UX 11.23 December 05 release.

pdsh would be a high performance option since it
would issue the command in parallel to the specified set of
systems. The target systems can be specified in a file, one
hostname per line.

You do have to configure rsh or non-interactive ssh for
pdsh. DSAU supplies the csshsetup tool to simply configuring
one-way or round-robin trust relationships for ssh.

Two other possible approaches:

- Use Systems Insight Manager. SIM has the Distributed Task
Facility (mxexec). This is conceptually similar to pdsh but
allows you to define role-based access control for
predefined commands/scripts.

- Use cfengine. cfengine is also included with HP-UX 11.23
December 05. You can use cfengine to distribute the script
to the managed clients and execute it there.

pete


dirk dierickx
Honored Contributor

Re: runnig shell script on many servers

clusterssh will perhaps fit your needs;

http://clusterssh.sourceforge.net/index.php/Main_Page