stagger ssh command to multiple machines


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users stagger ssh command to multiple machines
# 1  
Old 02-24-2009
stagger ssh command to multiple machines

Good day,

I am extracting information from Apache log files from 41 servers. Every day I have 7 cronjobs scheduled to do this for me and it works beautifully Smilie... only problem is that it takes about 6-9 hours to run through, as the script runs about 6 ssh commands for each box then goes to the next one.

I am sitting in the development environment and can only ssh in as readonly on the servers, which all sit in prodcution environment. I am not allowed to do anything on the production environment, so ssh is my only option for this one.

Here is a breakdown of my script structure
#!/usr/bin/ksh

ssh_function1()
}
Error_HTTP_403_cre()
{
if `test -f $sshExportFile`; then rm $sshExportFile ; else touch $sshExportFile ; fi
ErrorDesc="HTTP/1.1 403"
ssh readonly@$ServerIP 'YEAR=xx;DAY=xx;MONTH=xx;LMONTH=xx;for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \
16 17 18 19 20 21 22 23; grep -c "HTTP/1.1\" \"403" "/var/SP/log/apache/cre/access.log_$YEAR$MONTH$DAY_"*$i.gz ;done'>>$sshExportFile (Export file on dev box)
Sum_to_Oracle #Oracle insert function
echo "$ErrorDesc: $Value" >> $EFCREE
rm $sshExportFile
}

sshfunction()
{
ssh_function1 ; ssh_function2 ; ssh_function3 ; ssh_function#....
}

Servername="A"; serverip=1.1.1.1 ; sshfunction
Servername="B"; serverip=1.1.1.2 ; sshfunction
Servername="B"; serverip=1.1.1.3 ; sshfunction
#... and some more servers

The same commands run on all the servers.

Is there a way I can run the commands that after 5 minutes the script starts with the next server, while still running the sshfunction for the previous servers..Smilie

so... time=0
Servername="A"; serverip=1.1.1.1 ; sshfunction #kicks off and runs till finished
time=0+5
Servername="B"; serverip=1.1.1.2 ; sshfunction #kicks off and runs till finished
.. and so on and so forth.

Thanks in advance
msullivan
# 2  
Old 02-24-2009
Try this:

Servername="A"; serverip=1.1.1.1 ; sshfunction &
sleep 300
Servername="B"; serverip=1.1.1.2 ; sshfunction &
sleep 300
Servername="B"; serverip=1.1.1.3 ; sshfunction &
# 3  
Old 02-24-2009
But if I make it a solid background process...
Servername="A"; serverip=1.1.1.1 ; sshfunction &

Will that put all the functions in sshfunction() at the same time in the background?
As I have around 5 functions in the sshfunction and each of them on a
for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 loop.

I am assuming that putting the command sshfunction in the background (&), it will still execute all internal functions in the normal sequence..?
And not all 5 functions x 24 at the same time on that server..

Last edited by msullivan; 02-24-2009 at 10:34 AM..
# 4  
Old 02-24-2009
Thanks Perderabo
I tested the scripts and they work like a charm.. Now I just have to deal with output redirect... I'm sure >>$logFile 2>&1 & will do the trick.

Thanks again, for making my life a little easier.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Load different lib paths for different machines during ssh.

Greetings to every one, I have to access different clusters for computing. But the problem is their lib paths are different. :eek: How can i export some particular library paths for a particular machine ? For example Like cluster_1 (ip : 10.169.85.47) export LD_libPATH="/opt/CUDA" Like... (2 Replies)
Discussion started by: admax
2 Replies

2. AIX

Passwordless SSH problem with AIX machines

Hello, I am trying to setup passwordless nophrase ssh between two machines for the user id: oraprod here is what I did for a non-root user: oraprod whoami: oraprod Machine A: ssh-keygen -t dsa cat ~/.ssh/id_rsa.pub # GO TO MACHINE B create (16 Replies)
Discussion started by: filosophizer
16 Replies

3. What is on Your Mind?

What's your favorite SSH client to connect to UNIX/Linux machines?

I am curious about the most popular ssh client on Windows environment. Talking about me, I use PuTTY most of the time coupled with WinSCP to transfer files. But, I like Tera Term too. It has great drag-drop feature where you can drag a file/folder and drop on the window and it will transfer the... (14 Replies)
Discussion started by: admin_xor
14 Replies

4. UNIX for Dummies Questions & Answers

ssh autologin issue when both machines are having same ~home directory

Hi, I have two machines. M1 and M2 and having a generic id catadm, these two machines having common mount of /u/catadm directory. with this setup, ssh autologin is failing for me and asking me to enter password when i try autologin using this generc id from M1 to M2 catadm-M1$ ssh... (3 Replies)
Discussion started by: rbalaj16
3 Replies

5. UNIX for Dummies Questions & Answers

run script accross machines using ssh

Hi all I have to run certain set of commands on two machines, the two machines see the same home, it's mounted from the same place. The problem is that i have to ssh to a certain machine "which is slow unfortunately" that has the license to run a tool and i want to return to the original machine... (3 Replies)
Discussion started by: amr elhosiny
3 Replies

6. UNIX for Advanced & Expert Users

SSH connectivity between two machines with private key

Hi I have two machines Mac1 and Mac2 logging in with same user id and same private key. can anyone let me know how to connect these two machine using ssh . or SCP files to other machine :wall: (1 Reply)
Discussion started by: madankumar
1 Replies

7. Shell Programming and Scripting

how to ssh to remote unix machines using private/public key

hello, iam able to ssh to a linux server from a linux server called "machine1" using the private/public key method, so I dont need to enter any password when I run my script but iam not able to ssh from machine1 to a UNIX server, access is denied. note that I am using an application id which is... (6 Replies)
Discussion started by: wydadi
6 Replies

8. UNIX for Advanced & Expert Users

Synchronize DataBase Table Between Machines Via SSH?

Hello I have 2 servers that need a database table to be one way synchronized (server A needs to push the table to server B) I considered using a FEDERATED DB, but decided against it for my particular application (Server B has several apps that would be calling the table repeatedly, and a... (3 Replies)
Discussion started by: kettlewell
3 Replies

9. Linux

How to receive results from processes spawned on external machines using SSH

I am trying to get the number of cpus on a farm of linux boxes (about 100 of them) by 'sshing' to each of them and checking their /proc/cpuinfo file. So I have a local script localscript.sh on each of those 100 machines which retrieves the number of cpus in it by using its /proc/cpuinfo file.... (1 Reply)
Discussion started by: waavman
1 Replies

10. Red Hat

X11 forwarding problem between 2 RHEL4 machines with SSH

X11 forwarding problem between 2 RHEL4 machines with SSH Already configured the following on both machines under /etc/ssh Under sshd_config: UsePAM no AllowTcpForwarding yes Under ssh_config: ForwardAgent yes ForwardX11 yes ForwardX11Trusted yes ----------------------------- Using... (1 Reply)
Discussion started by: panggou
1 Replies
Login or Register to Ask a Question