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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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-23-2008 02:54 AM
Hummingbird Connectivity Division Releases Connectivity 2008 (EContent Magazine) iBot UNIX and Linux RSS News 0 06-17-2007 06:37 PM
My sql connectivity comp_rupesh Shell Programming and Scripting 0 03-14-2006 02:21 PM
Internet connectivity via Win-ICS Cameron UNIX for Dummies Questions & Answers 2 09-02-2004 12:11 PM
Dos system Connectivity arulprasad UNIX for Dummies Questions & Answers 8 02-03-2002 08:17 AM

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

Join Date: May 2007
Posts: 219
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
  #2 (permalink)  
Old 03-05-2008
grumpf grumpf is offline
Registered User
  
 

Join Date: May 2006
Posts: 101
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,
  #3 (permalink)  
Old 03-05-2008
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
Nmap option

I will check that option, any other ??
  #4 (permalink)  
Old 03-05-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
... 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?
  #5 (permalink)  
Old 03-06-2008
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
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 !!
  #6 (permalink)  
Old 03-06-2008
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
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
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 03:42 PM.


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