Hi guys ,
I want to write a script that will check the ssh connection can u suggest me best method to do that apart from ping (telnet ) on the ssh port or nmap i knw that but anything better than this ...
thanks in advance..
King
__________________________________ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250
King wrote:
Hi guys ,
I want to write a script that will check the ssh connection can u suggest me best method to do that apart from ping (telnet ) on the ssh port or nmap i knw that but anything better than this ...
Why do you want to do so? telnet is a neat way for checking it. However if you must use some script then try this python script:
-------------------------------------- #!/usr/bin/env python """ File: sshtest.py Usage: $ python sshtest.py """
import socket,os server='gnu.hbcse' port=22 srv=socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: srv.connect((server,port)) print('port '+str(port)+' @ '+server+' open') srv.close() except Exception: print('port '+str(port)+' @ '+server+' closed') --------------------------------------
-Anurag
-- ----------------------------------------------- __ __ gnu /noo/ n. Ox like antelope; (abbr.) /gnoo/ (recursive acronym) Gnu's Not Unix.
hi anurag,
Thanks for the code actually I wanted to have a script in perl or shell as i dont knw python. It will be something like this if the server is up work on it else goto next one in list.
Thanks, King
--- Anurag anurag@hbcse.tifr.res.in wrote:
King wrote:
Hi guys ,
I want to write a script that will check the
ssh
connection can u suggest me best method to do that apart from ping (telnet ) on the ssh port or nmap
i
knw that but anything better than this ...
Why do you want to do so? telnet is a neat way for checking it. However if you must use some script then try this python script:
#!/usr/bin/env python """ File: sshtest.py Usage: $ python sshtest.py """
import socket,os server='gnu.hbcse' port=22 srv=socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: srv.connect((server,port)) print('port '+str(port)+' @ '+server+' open') srv.close() except Exception: print('port '+str(port)+' @ '+server+' closed')
-Anurag
--
__ __
gnu /noo/ n. Ox like antelope; (abbr.) /gnoo/ (recursive acronym) Gnu's Not Unix.
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On Mon, 10 Jan 2005 20:16:10 -0800 (PST), "King" nightlife_king@yahoo.com said:
hi anurag,
Thanks for the code actually I wanted to have a
script in perl or shell as i dont knw python. It will be something like this if the server is up work on it else goto next one in list.
Save this shell script and execute. ----------------------------- #!/bin/bash ssh -X foo.bar ssh -X server.home ssh -X something.nothing ssh -X gnu.hbcse -----------------------------
This will try to connect to your ssh servers in that order. If it connects then it will ask for your password. You can enable public key authentication for use with ssh so that it does not ask for any password and uses your public key instead.
Generate ssh keys and copy them to ~/.ssh/ directory of server. then sign your key using: $ ssh-agent > /tmp/f $ source /tmp/f $ ssh-add
-Anurag
Thanks for the info dude, What i did was i used Net SSH Perl module to login to server and check the connection (with keys).Need to do error handliing now :(
Thanks. King
--- Anurag anurag@hbcse.tifr.res.in wrote:
On Mon, 10 Jan 2005 20:16:10 -0800 (PST), "King" nightlife_king@yahoo.com said:
hi anurag,
Thanks for the code actually I wanted to have
a
script in perl or shell as i dont knw python. It
will
be something like this if the server is up work on
it
else goto next one in list.
Save this shell script and execute.
#!/bin/bash ssh -X foo.bar ssh -X server.home ssh -X something.nothing ssh -X gnu.hbcse
This will try to connect to your ssh servers in that order. If it connects then it will ask for your password. You can enable public key authentication for use with ssh so that it does not ask for any password and uses your public key instead.
Generate ssh keys and copy them to ~/.ssh/ directory of server. then sign your key using: $ ssh-agent > /tmp/f $ source /tmp/f $ ssh-add
-Anurag
--
__ __
gnu /noo/ n. Ox like antelope; (abbr.) /gnoo/ n. (recursive acronym) Gnu's Not Unix.
__________________________________ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250
On Tue, 11 Jan 2005 20:47:04 -0800 (PST), "King" nightlife_king@yahoo.com said:
Thanks for the info dude, What i did was i used Net SSH Perl module to login to server and check the connection (with keys).Need to do error handliing now :(
http://www.perldoc.com/perl5.8.4/pod/perl.html
btw, what are you trying to do exactly? I couldn't understand anything from your past three mails...
-Anurag
hi,
THe senario is that we update data on our servers through rsync (through ssh ) and a shell scripts is used to do that but the problem is if one server is down (connection fails) the script dies so rest servers (after the down server ) dont get updated. So what i was trying was to check the proper ssh connections to the server and supply the working server list to this script.
King...
--- Anurag anurag@hbcse.tifr.res.in wrote:
On Tue, 11 Jan 2005 20:47:04 -0800 (PST), "King" nightlife_king@yahoo.com said:
Thanks for the info dude, What i did was i used
Net
SSH Perl module to login to server and check the connection (with keys).Need to do error handliing
now
:(
http://www.perldoc.com/perl5.8.4/pod/perl.html
btw, what are you trying to do exactly? I couldn't understand anything from your past three mails...
-Anurag
--
__ __
gnu /noo/ n. Ox like antelope; (abbr.) /gnoo/ n. (recursive acronym) Gnu's Not Unix.
__________________________________ Do you Yahoo!? Yahoo! Mail - Easier than ever with enhanced search. Learn more. http://info.mail.yahoo.com/mail_250
On 12/01/05 02:05 -0800, King wrote:
hi,
THe senario is that we update data on our servers through rsync (through ssh ) and a shell scripts is used to do that but the problem is if one server is down (connection fails) the script dies so rest servers (after the down server ) dont get updated. So what i was trying was to check the proper ssh connections to the server and supply the working server list to this script.
Yikes. You should never have the master push the updates out. Instead have the clients pull in updates on a regular schedule.
Devdas Bhagat
On Mon, Jan 10, 2005 at 10:18:57AM -0800, King wrote:
I want to write a script that will check the ssh connection can u suggest me best method to do that apart from ping (telnet ) on the ssh port or nmap i knw that but anything better than this ...
What is the problem you are trying to solve? Why do you need a persistent ssh connection?