LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with a script? (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-a-script-781074/)

your_shadow03 01-09-2010 11:22 AM

Help with a script?
 
I have a monitoring script like snippet below:
Code:

sudo sh customer@IP "perl ./monitoring-script bust_page | /home/john/mailhim.pl
Now The issue is I have 10 Web and 10 DB Servers.
All I used to open different putty and run this command 20-times on the monitoring Server.This script which I run on Local Monitoring server, run on remote server, fetches the data and bring it back to local monitoring server and execute with local script called /home/john/mailhim.pl
As of now I do need to provide couple of 20 times and thats cumbersome when connectivity goes down.I follow up like this:

Code:

Putty Session-1
sudo sh customer@10.14.236.91"perl ./monitoring-script bust_page | /home/john/mailhim.pl
Putty Session- II
sudo sh customer@10.14.236.92 "perl ./monitoring-script bust_page | /home/john/mailhim.pl
.
.
.
sudo sh customer@10.14.236.120 "perl ./monitoring-script bust_page | /home/john/mailhim.pl

Guys, Can you help me with writing a single script which can execute at a single shot.

GooseYArd 01-09-2010 11:37 AM

there are a slew of tools that let you run a command on sets of servers at once via ssh.

http://freshmeat.net/projects/pssh/

http://tentakel.biskalar.de/

if you don't need them to run strictly in parallel, why not just use a for loop:

for octet in 91 92 93; do ssh foo@10.14.236.$octet:"remote command"; done

If you need to run these from the machine with putty, I would install Cygwin and just script it via bash with openssh instead of putty.

your_shadow03 01-09-2010 11:48 AM

What about the password?Will it ask for single time for password?

donnied 01-09-2010 06:46 PM

Do you have ssh keys set-up?

http://www.debian-administration.org/articles/152

I like this python app for simultaneously controlling multiple ssh connections.
http://www.noah.org/wiki/Pexpect

GooseYArd 01-09-2010 06:54 PM

shadow: once you've followed donnied's advice and set up key auth for ssh, then you want to load the key you create into an ssh-agent. Any ssh connections you make once the agent is running won't require you to type any passwords- the decrypted key sits in the agent, and ssh communicates with the agent at login time to get the key.

your_shadow03 01-10-2010 04:23 AM

I don't have root credentials with the production server.
Can I use my user credentials for the same?
I have root access with the local Monitoring Server but not for production servers.
Can it be possible without copying anything to be monitored servers.

GooseYArd 01-10-2010 07:38 AM

Yes, the only thing that needs to be adjusted on the servers you are connecting to is to create an .ssh/authorized_keys file in the home directory of the user you connect as. As long as sshd is configured to do key auth (it almost always is), no other changes are necessary.


All times are GMT -5. The time now is 11:05 AM.