Command to run across servers

Hi,

I have to run several unix commands like lsof or sed and need to execute across different servers as part of my monitoring tasks.

There are around 40 Unix Servers. It is really cumbersome to run those command on several servers.

can some help me in this regard. Is it possible to run these commands on sitting on one server?

Thanks in Advance.

Regards, John.

You might want to use passwordless communication via ssh. There is plenty of instructions on this forum on it and on the web. Use the search function of this forum please.

Well, for monitoring, it might be simpler, architecturally, to put a cron calling a script on each host to send the data to you, perhaps by nfs, ssh2, scp2, email. With NFS, the script and data could all be mounted locally. A central script would ensure everyone is reporting regularly, and perhaps load the data into an RDBMS for reporting and trend monitoring.

I would appreciate if you could post few example. However, i do not want to put script on each host.

You might again end up keeping all those script updated new commands.

If you do not want nfs or remote scripts, you can ship the scripting from a central script:

 
while read host
do
 echo ". ./.profile
    -- all commands you want to run --
     " | ssh2 $host ksh >>log_dir/$host.$(date '+%Y''%m''%d-%H%M').log 2>&1
    if [ $? != 0 ]
    then
      echo "$host Down!"
    fi
done <host_list_file

I prefer echo '...'"..."'...' | over <<!, keeping stuff flowing left to right, with switch to "..." where I want local interpretation, like $var, `` or $(), not piles of \escapes. Everything inside '...' is pretty stable and low cost for the shell to produce, so start there, go to "..." as necessary, and your life will have fewer unpleasant surprises.

Here's another vote for passwordless communication via ssh.

Write a wrapper for SSH. Then you can run commands from a central server across your whole environment.

I made options to run all the commands in parallel; consolidate the output from like servers; and node groups.

My idea is not original, I copied dsh from AIX (and PSSP or CSM).

The ssh compression option is appropriate if the reports get long. It improves the security, too.

---------- Post updated 2011-01-13 at 01:55 PM ---------- Previous update was 2011-01-12 at 04:29 PM ----------

Modified for parallel operarion. Logs were already separate for child reports. The "| cat" holds on until every subshell exits.