LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-16-2010, 11:57 PM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
A remote machine script?


I have centOS Machine which is my monitoring Server. I run the belowmentioned command to ssh to remote production server and get back those parametrics metrics.
All I am doing now is manually running these commands 10-15 times .
I am a sudo user in that production.How can I write a script to make it in one shot?


Code:
ssh tom@10.14.236.151 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.26 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.25 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.146 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.18 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.20 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.146 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.146 "perl ./monitor count" | /mont/ground/mail.pl
ssh tom@10.14.236.20 "perl ./monitor count" | /mont/ground/mail.pl
I explored and took a look at http://kbase.redhat.com/faq/docs/DOC-9195
I tried running :

ssh-keygen

And,

ssh-copy-id -i $HOME/.ssh/id_rsa.pub user@

And they worked fine.
I can also see authorized_key in remote Machine.
Now what next?

Last edited by your_shadow03; 01-17-2010 at 01:18 AM.
 
Old 01-17-2010, 04:06 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
How about a little bash loop?
Code:
#!/bin/bash
ips="10.14.236.151 10.14.236.26 10.14.236.25"
for ip in $ips ; do
   ssh tom@${ip} "perl ./monitor count" | /mont/ground/mail.pl
done
Add as many addresses as you like to the ips variable.

Evo2.
 
Old 01-17-2010, 08:56 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
Rep: Reputation: 51
What about the ssh password?
 
Old 01-17-2010, 05:05 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Basically, you should be ok with password-less authentication. Have you tried to connect to the machine where you copied the public identity with the mentioned ssh-copy-id command? Does it still ask for a password? If this is the case, you have to check the permissions of your private key and of the .ssh directory. More chances to retrieve some useful information if you run ssh using the -v (verbose) option and "listen to" the talk between the local and the remote machines
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need script to invoke on remote machine barunparichha Linux - Software 2 05-15-2009 10:53 AM
How to run a script to a remote linux machine from a windows machine squirrel001 Linux - Newbie 5 05-04-2009 07:06 PM
Script for connecting to the remote machine Uday123 Linux - Networking 5 01-02-2006 09:43 PM
script to monitor process on remote machine kencha Linux - Newbie 6 01-07-2005 01:07 PM
telneting remote machine from a shell script sanjith11 Programming 11 05-26-2004 07:50 AM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration