The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash Script to check Remote Host Connection zulfikarmd UNIX for Dummies Questions & Answers 5 04-16-2008 06:53 AM
How to delete the files from local host to remote host krishna176 SUN Solaris 3 03-24-2007 04:48 PM
FTP - Connection Closed By Remote Host mouglybean IP Networking 1 10-26-2004 09:15 AM
Connection to host lost goose UNIX for Dummies Questions & Answers 2 06-04-2002 07:32 PM
connection to host lost nbiketi UNIX for Dummies Questions & Answers 1 04-25-2001 11:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-18-2008
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
check ssh connection to remote host

I am using KSH and I need to check whether the remote host has been configured with ssh public key. Is there any way we can check inside a script?
  #2 (permalink)  
Old 05-18-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
man test
Code:
host=host
ssh $host "echo 2>&1"
test $? -eq 0 && echo $host OK || echo $host NOK
  #3 (permalink)  
Old 05-18-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Of course, that's a Useless Use of Test $?

Code:
ssh $host "echo 2>&1" && echo $host OK || echo $host NOK
Absence of a public key is by no means the only way the ssh command can fail, so this is an approximation at best; but maybe it's sufficient.
  #4 (permalink)  
Old 05-18-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Quote:
Originally Posted by era View Post
Of course, that's a Useless Use of Test $?
This time I use test only as example to show him how to use the exit status.
  #5 (permalink)  
Old 05-19-2008
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
Great thanks , This is helpfull.
  #6 (permalink)  
Old 05-20-2008
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
I got a problem here

I removed the public key config on the ssh server and then tried

ssh root@$host "echo 2>&1" && echo "OK" || echo "NOK"

But it came out asking password . which I dont want , what I wanted is even if its asked passwd its should come out with a non-zero exit satus.

--------------------------------------------------------------------
Now let say how I got it implemented , even though a twisted way

if [ -f $HOME/.ssh2/ssh2_config ]
then
mv $HOME/.ssh2/ssh2_config $HOME/.ssh2/ssh2_config.bkp
echo "QuietMode yes\nBatchMode yes\nConnectTimeout 4" > $HOME/.ssh2/ssh2_config
else
echo "QuietMode yes\nBatchMode yes\nConnectTimeout 4" > $HOME/.ssh2/ssh2_config
fi

ssh -l root $R_HOSTNAME "date" > /dev/null
CONN_STATUS=$?

And if the RC is 66 , then it mean it had asked passwd and not got passwd within in the timeout period. Andas usual 0 as success.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0