The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Dos-Unix Connectivity shekhar_ssm Shell Programming and Scripting 1 01-22-2008 10:54 PM
Hummingbird Connectivity Division Releases Connectivity 2008 (EContent Magazine) iBot UNIX and Linux RSS News 0 06-17-2007 03:37 PM
My sql connectivity comp_rupesh Shell Programming and Scripting 0 03-14-2006 10:21 AM
Internet connectivity via Win-ICS Cameron UNIX for Dummies Questions & Answers 2 09-02-2004 09:11 AM
Dos system Connectivity arulprasad UNIX for Dummies Questions & Answers 8 02-03-2002 04:17 AM

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

Join Date: May 2007
Posts: 211
SSH Connectivity script

Hi all,

I have developed a script to list out the servers that is not able to connect to the remote host.

The problem with this script is it, if the remote server ask for a password it gets struck there. It works only if the server name is invalid

Ex: Lets say ssh -q test@test "exit" < /dev/null the script will throw that test server is invalid.

Lets say now UserA and ServerA is valid but when we ssh to the server, it ask for a password and script hangs

ssh -q UserA@ServerA "exit" < /dev/null

Code

Code:
check_ssh()
{
        ssh -q $1@$2 "exit" < /dev/null
        [ $? -ne "0" ] && return 1 || return 0
}

INP_FILE=Config.ini

for line in $(grep -v "^#" $INP_FILE | cut -d',' -f2,5 | sort | uniq)
do
        myUser=$(echo $line| cut -d',' -f2)
        myServer=$(echo $line| cut -d',' -f1)
        check_ssh $myUser $myServer
        [ $? -eq "1" ] && echo "Please check !!! $myServer - $myUser"
done
echo " *** END *** "
exit
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-05-2008
Registered User
 

Join Date: May 2006
Posts: 95
i understand you basic idea is to use ssh do a dummy connect to figure out if an sshd is running on the other side ?

why do you not use nmap ? it simply cheks if there is a service available,
Reply With Quote
  #3 (permalink)  
Old 03-05-2008
Registered User
 

Join Date: May 2007
Posts: 211
Nmap option

I will check that option, any other ??
Reply With Quote
  #4 (permalink)  
Old 03-05-2008
System Shock's Avatar
Registered User
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 367
... but what are you exacly testing for?
Whether you can connect or not?
Whether sshd is running or not?
If you can connect to the hosts without a pasword using ssh keys?
Reply With Quote
  #5 (permalink)  
Old 03-05-2008
Registered User
 

Join Date: May 2007
Posts: 211
Quote:
Originally Posted by System Shock View Post
... but what are you exacly testing for?
Whether you can connect or not?
Whether sshd is running or not?
If you can connect to the hosts without a pasword using ssh keys?
I want to check if we can ssh to a remote host and execute our statements. This is just a function block which checks for whether we can ssh into a server before executing our statements.

I just want to capture the server names that we are not able to ssh, so that we can skip those servers from executing the command.

Hope this makes clear !!
Reply With Quote
  #6 (permalink)  
Old 03-06-2008
Registered User
 

Join Date: May 2007
Posts: 211
Smile Got it !!!

Code:
check_ssh()
{
        ssh -q -o "BatchMode=yes" $1@$2 "exit" < /dev/null
        [ $? -ne "0" ] && return 1 || return 0
}

INP_FILE=Config.ini

for line in $(grep -v "^#" $INP_FILE | cut -d',' -f2,5 | sort | uniq)
do
        myUser=$(echo $line| cut -d',' -f2)
        myServer=$(echo $line| cut -d',' -f1)
        check_ssh $myUser $myServer
        [ $? -eq "1" ] && echo "Please check !!! $myServer - $myUser"
done
echo " *** END *** "
exit
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:05 AM.


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