LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-14-2010, 01:22 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Error Executing a script(SSH problem)


Hi i m writing a script which will fetch data from different machines and display it on single terminal.

I have created a file named SERVERNAMES containing ip address of machines i need to monitor.
Then for every IP i m issuing ssh command to get date on that machine.
However When i m trying it on the script it is just giving me output of first server and it is ignoring rest servers mentioned in file.

ssh works find without password for all machines mentioned in SERVERNAMES.


Code:
# cat SERVERNAMES
10.180.45.231
10.180.45.235
10.180.45.238
10.180.45.211
Script
Code:
#!/bin/bash

while read line
do
#Calculate Load on remote machine.
Date=`ssh -T -q $line date`
echo "Date on $line is:$Date"
done < SERVERNAMES
Code:
output.
Date on 10.180.8.231 is:Wed Jul 14 10:48:46 IST 2010
please help as i m not getting the output for .
Code:
10.180.45.235
10.180.45.238
10.180.45.211
Is there anything wrong in ssh?
 
Old 07-14-2010, 01:35 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Did you set up authentication using SSL keys or does your script ask you for the password to connect to the remote server? If it asks you for the password then your script will exit after the first run. To avoid this you could either set up passwordless key authentication or use a tool like sshpass.

Kind regards,

Eric
 
Old 07-14-2010, 01:38 AM   #3
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
You could try:

Code:
for host in $(cat SERVERNAMES)
do
   ....

done
As an alternative, func provides a nice encrypted control channel, you can run any command you like against an arbitrary set of hosts:

Code:
func "test[1-5].mydomain.com" call command run '<your_command_here>'
Ref: https://fedorahosted.org/func/

cheers
 
Old 07-14-2010, 02:14 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by pinga123 View Post
Hi i m writing a script which will fetch data from different machines and display it on single terminal.

I have created a file named SERVERNAMES containing ip address of machines i need to monitor.
Then for every IP i m issuing ssh command to get date on that machine.
However When i m trying it on the script it is just giving me output of first server and it is ignoring rest servers mentioned in file.

ssh works find without password for all machines mentioned in SERVERNAMES.


Code:
# cat SERVERNAMES
10.180.45.231
10.180.45.235
10.180.45.238
10.180.45.211
Script
Code:
#!/bin/bash

while read line
do
#Calculate Load on remote machine.
Date=`ssh -T -q $line date`
echo "Date on $line is:$Date"
done < SERVERNAMES
Code:
output.
Date on 10.180.8.231 is:Wed Jul 14 10:48:46 IST 2010
please help as i m not getting the output for .
Code:
10.180.45.235
10.180.45.238
10.180.45.211
Is there anything wrong in ssh?

The problem with your version is that you're reading
from STDIN, and ssh reads the rest of your file.

You can either use kbp's method, or add an "-n"
switch to your ssh invocation.


Cheers,
Tink
 
Old 07-14-2010, 02:38 AM   #5
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by Tinkster View Post
The problem with your version is that you're reading
from STDIN, and ssh reads the rest of your file.

You can either use kbp's method, or add an "-n"
switch to your ssh invocation.


Cheers,
Tink

after adding -n option its working.
Code:
#!/bin/bash

while read line
do
#Calculate Load on remote machine.
Date=`ssh -T -q -n $line date`
echo "Date on $line is:$Date"
done < SERVERNAMES
 
Old 07-14-2010, 01:54 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And again. Please mark your solved threads as solved.
While I can do this as a mod of this forum, and I have
partaken in the thread I'll notice it, it's not always
the case that a mod will notice or take care of it.

Please be considerate of others, and mark your resolved
threads as resolved.



Cheers,
Tink
 
  


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
[SOLVED] Error Executing the script. pinga123 Linux - Newbie 3 07-08-2010 11:34 PM
Error executing Perl/CGI script loftus49 Fedora 6 06-10-2010 04:41 AM
Sntax error : unexpected end of file while executing shell script priyankarathi Linux - Newbie 5 04-21-2009 02:33 AM
executing a script when logging via ssh rubby1 Linux - General 8 10-06-2005 04:12 PM
Executing PHP script- error message vfulco Linux - Newbie 3 07-13-2004 11:55 PM


All times are GMT -5. The time now is 12:40 AM.

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