SSH Connectivity script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users SSH Connectivity script
# 1  
Old 03-05-2008
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  
Old 03-05-2008
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  
Old 03-05-2008
Nmap option

I will check that option, any other ??
# 4  
Old 03-05-2008
... 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  
Old 03-06-2008
Quote:
Originally Posted by System Shock
... 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  
Old 03-06-2008
Bug 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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SSH Connectivity

I am trying to setup a password less connection from a Linux server to Window server and will be using a script to scp a file without using password. Linux Server (source) servername : testlinux id : testbatch Windows Server (Target) servername : testwin id : testwinlogin I copied... (5 Replies)
Discussion started by: dr46014
5 Replies

2. Shell Programming and Scripting

ssh connectivity

Hi i have two servers name as ser1 ser2 with sudo user name "test" I want to ssh to the ser2 without using apassword am login with normal ssh method likes ssh test@ser2 i got the id_rsa.pub from ser1 and pasted int authorized_keys in ser2. and while connecting got one RSA key fingerprint .... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

3. Shell Programming and Scripting

ssh connectivity

Hi, I have two unix servers named as uni115.net uni116.net In both the boxes, I have sudo access to access some file. From uni115.net , I need to login to uni116.net through script And while running my main script , it wont ask the password for login to another machine. How can we do... (1 Reply)
Discussion started by: ckchelladurai
1 Replies

4. UNIX for Advanced & Expert Users

SSH connectivity between two machines with private key

Hi I have two machines Mac1 and Mac2 logging in with same user id and same private key. can anyone let me know how to connect these two machine using ssh . or SCP files to other machine :wall: (1 Reply)
Discussion started by: madankumar
1 Replies

5. UNIX for Advanced & Expert Users

SSH/RCP connectivity error

Hi Team, Hope you will be able to help me out with this problem. Our sun solaris 9 system receives Idoc files from another xxx system through RCP. But before RCP they establish an SSH connection. Since today morning they are not able to establish connection and is getting an error as pasted below... (0 Replies)
Discussion started by: anitha111
0 Replies

6. Shell Programming and Scripting

Check connectivity script

This past weekend I had some issues with my ISP. So for future purpose I'm going to have some logging on my internet so I'm able to attach log files to my complaint email if this issue reoccurs. Decided to do a simple ping script that runs every 5 or 10 min with crontab if ping fail write date... (5 Replies)
Discussion started by: chipmunken
5 Replies

7. Shell Programming and Scripting

Verifying SSH connectivity in a script

Hi everyone, I'm trying to write a korne shell script that takes the IP address of a remote server as an argument and logs into that server if RSA key has been setup properly, otherwise exits if RSA key is not set for that server. I don't want the script to get stuck with Password prompt... (1 Reply)
Discussion started by: omd
1 Replies

8. Shell Programming and Scripting

ssh connectivity problem

Hi All, i have problem with ssh i have three server(linux box) like below server A server B server C i did ssh(Private key & Public key) for passwordls .. i did for server A to Server B connection without any issue now i am able to connect server A to server B without... (6 Replies)
Discussion started by: Shahul
6 Replies

9. Shell Programming and Scripting

Script to check connectivity

I want to write a script to check if a unix box say abc.tdc.cin.net can be connected or not on certain port say 22. right know i have to telnet them manually from DOS prompt and if it is successful then isay it is connected. Also to check Database connectivity I am using tnsping From DOS prompt.... (3 Replies)
Discussion started by: kukretiabhi13
3 Replies
Login or Register to Ask a Question