The UNIX and Linux Forums  

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 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 03:53 AM
How to delete the files from local host to remote host krishna176 SUN Solaris 3 03-24-2007 12:48 PM
FTP - Connection Closed By Remote Host mouglybean IP Networking 1 10-26-2004 06:15 AM
Connection to host lost goose UNIX for Dummies Questions & Answers 2 06-04-2002 04:32 PM
connection to host lost nbiketi UNIX for Dummies Questions & Answers 1 04-25-2001 08:45 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-17-2008
Registered User
 

Join Date: Apr 2008
Posts: 13
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?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-18-2008
 

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

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,111
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.
Reply With Quote
  #4 (permalink)  
Old 05-18-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 463
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.
Reply With Quote
  #5 (permalink)  
Old 05-19-2008
Registered User
 

Join Date: Apr 2008
Posts: 13
Great thanks , This is helpfull.
Reply With Quote
  #6 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Apr 2008
Posts: 13
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0