Testing ssh connection from KSH script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Testing ssh connection from KSH script
# 1  
Old 05-30-2005
Testing ssh connection from KSH script

Hi. I have a kornshell script that runs on a daily basis as a cron job. Part of what the script does is copy the folder contents from another server to the current server (server where KSH script is running).

I have a scp command, as follows:

scp $REMOTE_HOST:$REMOTE_FILE_DIR/* $TMP_DIR

How would I verify the connection to the "remote host"? In other words, I don't want to run the SCP command unless it can connect to the remote host. How would I do this?

Thanks,
- Dylan
# 2  
Old 05-30-2005
Dylan,

You can try to ping to the remote host, and connect only if the system is up.
# 3  
Old 05-30-2005
Thanks. If I open a Putty session and logon to the server where the KSH script runs from, and type in "ping mgftp01", it does nothing - it just hangs. I know the server is up because I can logon to it. However, maybe I just don't understand all the options of the PING command. Can you point me in the right direction?

Also, is it possible to have a server not accept incoming PING requests?

Thanks again,
- Dylan
# 4  
Old 05-31-2005
Quote:
Originally Posted by dmilks
Thanks. If I open a Putty session and logon to the server where the KSH script runs from, and type in "ping mgftp01", it does nothing - it just hangs. I know the server is up because I can logon to it. However, maybe I just don't understand all the options of the PING command. Can you point me in the right direction?

Also, is it possible to have a server not accept incoming PING requests?

Thanks again,
- Dylan
Hi !
Well... depening on the firewall, the server may ignore all or part of the ICMP signals and, probably, this is your case.
About what you want... I don't know a simple solution for this... but, don't you have some other services on the server ? somethin that doesn't require a username and a passowrd... like finger or http... if you do, you can make a script or something that will check if it can connect to the server on the specified port and if it can, you can run your command ;-)
# 5  
Old 05-31-2005
The problem (i have the same one, btw.) is more difficult than that: it is possible to make sure the remote server is up and running, but I don't know of a simple way to make sure the keys for a secure connection are exchanged.

ssh <somewhere> -c '<command>'

will work fine if the keys are exchanged, but will hang if they are not. In this case ssh (scp, ...) will present an interactive screen asking to enter the password - which will hang the script, since it will never answer to that.

bakunin
# 6  
Old 06-01-2005
It seems to me different issues Dylan and Bakunin are talking about.

Dylan's concern is how to verify the remote service (sshd, specifically) is alive before trying to request the service. This can be done by Nagios script, check_ssh.

Bakunin's question is more complicated. You may need google "sshd key without password host authentication". There are hundreds of postings/docs explaining this.

Cheers,
Tom
# 7  
Old 06-01-2005
@Tom: Many thanks, the explanations are good, but i got so far already.

My (at least my, I don't know about Dylan but suppose he will run into similar problems) problem is: I can at one point make sure i have exchanged all the necessary keys and then run some script. But i cannot ensure this for any future and for any host because sometimes the exchanged keys become invalid and the next execution of ssh would ask for a new authentication.

For example: I have long worked on IBMs SP/2 platform and there was a mechanism called "distributed shell". It was a (kerberized) wrapper around rsh with which it was possible to execute a command on one, several or all nodes simultaneously. Issuing 'dsh "date"' would result in an output like:

# dsh "date"
foo1: Wed Jun 1 09:33:18 MSZ 2005
foo2: Wed Jun 1 09:33:19 MSZ 2005
foo3: Wed Jun 1 09:33:19 MSZ 2005
foo4: Wed Jun 1 09:33:18 MSZ 2005
...

Since the SP/2 (and with it PSSP and its successor Cluster/1600) is long gone I tried to write a script imitating this behavior. Neither does it run regularly nor does it always run on the same list of machines. The script is working perfectly as long as all the keys are (AND STAY) exchanged, but once a key is missing the script hangs.

Maybe i'm overseeing something really stupid here, but i haven't found out what to do in this case.

*sigh* back then in the good old days of kerberos things were less complicated - but then, who'd have guessed back then that once these times would be regarded as 'good'? ;-))

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

2. UNIX for Dummies Questions & Answers

Ftps connection by ksh script

Hi, I'm trying to access to FTP SERVER over SSL with this script unix : (credentials are correct) #!/usr/bin/ksh USER="test" PASSWORD="pwdtest" IP="**.***.*.***" ftp -s $IP 990 << EOF >>log_ftp user $USER $PASSWORD bin passive EOF but seems that credentials are not passed... (2 Replies)
Discussion started by: nash83
2 Replies

3. Shell Programming and Scripting

ssh connection through shell script with no interruption

Hi all, I need ssh in shell script. My requirement is: - Take user_name and password from user (in PHP) - Pass this to shell script which will: - connect via ssh - Run sql query - Pass the results back in PHP - Put the results to website. I know PHP has libraries for ssh and ftp, but... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

4. Shell Programming and Scripting

Passing password in script for ssh connection - no except

Used the script posted on forum - unix.com/shell-programming-scripting/21597-script-change-passwords-same-user-multiple-servers.html but the last question posted on this seems to be still unanswered, tried different things with no success, can someone help giving an way to pass the password via... (5 Replies)
Discussion started by: sapadmin
5 Replies

5. Shell Programming and Scripting

testing postgres connection in shell script

I have a script that does db query in postgres. I'm trying to put in some error checking in the script. I keep running into the password prompt problem where when invalid credentials/or database is put it, it would prompt me for a password which hangs the script. Is there a way that I can check for... (0 Replies)
Discussion started by: zerofire123
0 Replies

6. Shell Programming and Scripting

Mysql command after a SSH connection (Script)

Hi all, Im new at scripting and i need to run a few commands at work every hours so i decide to make a script but on 1 of the steps i have a the follwoing problem: The command i do is this: #!/bin/bash ssh root@asdasd001 'mysql -h A-db-1 -uroot -password --execute "show slave status"'... (3 Replies)
Discussion started by: Aparicio
3 Replies

7. Shell Programming and Scripting

Testing connection with a script

I have a box that has to start dhcpd when a certain connection is down and stop the dhcpd when the connection is up again. I would appriciate any help making this script: From server A: ping server B if connection is ok then do nothing if connection is not ok then start dhcpd until... (8 Replies)
Discussion started by: KimJensen
8 Replies

8. Shell Programming and Scripting

Testing success of AWK code in KSH script

I need a bit of help here on something simple. I have a KSH script (must be KSH) that needs to change 2 positional variables in a CSV script. The CSV script looks like this: 00001,010109,01/01/2009 00:01:01 00008,090509,09/05/2009 13:47:26 My AWK script will change $2 and $3 based... (4 Replies)
Discussion started by: kretara
4 Replies

9. Shell Programming and Scripting

ssh connection script

Hi all, I'm writing a script that chooses the best computer available in an open lab. The script works great except every now and then there is a dead computer in the lab that begins the ssh handshaking, but freezes after the following: debug1: Offering public key: When the script happens... (2 Replies)
Discussion started by: x-375HK-x
2 Replies

10. Shell Programming and Scripting

Remote SSH Connection Using Script

Hi, I am new to Shell Scripting. Can anybody help me in writing a Script Which Could Login from a Unix box to a Remote Unix box which accepts the user credentials automatically and display the result for checking the Disk Space Utilisation (Without running any SSH agent). (1 Reply)
Discussion started by: ajith_tg
1 Replies
Login or Register to Ask a Question