Command to run across servers


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Command to run across servers
# 1  
Old 01-10-2011
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.
# 2  
Old 01-10-2011
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.
# 3  
Old 01-10-2011
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.
# 4  
Old 01-10-2011
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.
# 5  
Old 01-11-2011
If you do not want nfs or remote scripts, you can ship the scripting from a central script:
Code:
 
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.
# 6  
Old 01-11-2011
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).
# 7  
Old 01-13-2011
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 ----------

Quote:
Originally Posted by DGPickett
If you do not want nfs or remote scripts, you can ship the scripting from a central script:
Code:
 
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 2>&1 | cat -u

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.
Modified for parallel operarion. Logs were already separate for child reports. The "| cat" holds on until every subshell exits.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run simple single command on multiple Linux servers?

Hi All, How can i run a single command on multiple servers with or without giving credentials. I have a file(servers.txt) which has got list of servers and i want to run a command lsb_release -dr on all these servers and get output of those servers against each server. I tried below code... (9 Replies)
Discussion started by: darling
9 Replies

2. Shell Programming and Scripting

Run a shell script on all 15 servers at the same time?

We have 15 servers. Hostnames for these 15 servers are stored in a text files and loop through each server to connect to the remote server and run a command, but this loop process runs the command one after another. However, the requirement is to run the same command on all 15 servers at the same... (10 Replies)
Discussion started by: laknar
10 Replies

3. Shell Programming and Scripting

Run a script on multiple servers

I need to run a script on a bunch of remote servers. how can this be done without ssh into each individual server and run it its under /sbin/script.sh on each server (1 Reply)
Discussion started by: tdubb123
1 Replies

4. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

5. Shell Programming and Scripting

Run a script in parts on 2 servers

Hi all, I have a task for which I need to run some commands on one server1 and then jump from the server1 (using ssh and asking user to enter login credentials manually for server2 server) to server2 and run some commands there and exit. I know the script I need here but problem is when I... (5 Replies)
Discussion started by: pat_pramod
5 Replies

6. Shell Programming and Scripting

Need a script to run on multiple mail servers..

Hello, I am a Unix newbie and I need a script in which I can run a command on multiple servers at work. The command is to start a storage process and I am sick of doing it manually on all servers.. Here's the command: /opt/bss/bin/snmptable -CB -v2c -c P67LzuBm hostname hrStorageTable... (4 Replies)
Discussion started by: kinyyy
4 Replies

7. Shell Programming and Scripting

How do you guys run scripts against ALL your servers ?

I have 2000 odd servers (may of which are virtualisations) and if we want to run a script against all of them or distribute files/install software to all of them, we currently perform a simple for loop against a managed list of our servers called SLIST for host in `cat SLIST` ; do ssh $host... (1 Reply)
Discussion started by: rethink
1 Replies

8. Shell Programming and Scripting

How to run same script on multiples servers

Hi All, I have some script that run some commands and send results to my email. I want to run same script on mulitiple servers. How can I do that. I know there is an option "ssh". But I'm not quite sure how to use it in the script. And also. scripts has some parameters like following, if :... (10 Replies)
Discussion started by: s_linux
10 Replies

9. Shell Programming and Scripting

ksh to run servers

I want to write a Kshell program which will start the servers(Oracle,DataIntegrator). Can anybody help me with this? I would appreciate your help. Thanks in advance (0 Replies)
Discussion started by: pari111222
0 Replies

10. UNIX for Dummies Questions & Answers

I would like to know Would you run the ‘identd’ daemon on UNIX servers?

Would you run the ‘identd' daemon on UNIX servers? can you please Explain. thanks in advance! (3 Replies)
Discussion started by: xoxouu
3 Replies
Login or Register to Ask a Question