Connection Test Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Connection Test Script
# 1  
Old 08-19-2009
Connection Test Script

I am writing a script to do some conditional logic based on the results of a connection test. I need to capture the output of netcat, the 3 expected conditions are as follows. I need to capture the output of this command. I could write this to a file, but I would like to do it clearer if possible.

nc -w 2 -nzv 127.0.0.1 80-80
(UNKNOWN) [127.0.0.1] 80 (?) : Connection refused

nc -w 2 -nzv 127.0.0.1 80-80
(UNKNOWN) [127.0.0.1] 80 (?) : Connection timed out

nc -w 2 -nzv 127.0.0.1 80-80
(UNKNOWN) [127.0.0.1] 80 (?) open

basically I am looking for

if "refused" then x
if "timed out" then y
if "open" then z

But I don't know how to capture the results of the netcat.

I appreciate any help you can provide.
# 2  
Old 08-19-2009
Code:
variable=`nc -w 2 -nzv 127.0.0.1 80-80 2>&1`
do something with $variable

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

How can I test ldap connection to DC?

Hi all, Recently, I configured LDAP loadbalancing. So I need to test it from HPUX servers. But I don't know how to to it. I know many ldap connection tools such as ldap browser etc. But it's HPUX 11.31, so please share your practices. Thanks (1 Reply)
Discussion started by: sembii
1 Replies

2. UNIX for Dummies Questions & Answers

Shell Script to test telnet connection using port

Hello, I need to test telnet connections using port number for few hosts. Could you please help me? Thanks !! (1 Reply)
Discussion started by: skhichi
1 Replies

3. UNIX for Dummies Questions & Answers

Test new DSN connection to sql server

I installed an odbc driver and created a DSN to connect to a sql server database on AIX 6. I want to know how to test the DSN from the command line. What syntax or commands do I use? ---------- Post updated at 11:44 AM ---------- Previous update was at 08:26 AM ---------- OK I figured out how... (9 Replies)
Discussion started by: Jdbrown239
9 Replies

4. UNIX for Dummies Questions & Answers

Test Connection to hosts

i have about 3500 hosts/devices which i monitor. i monitor them from one host. we'll call this one host HOSTA. HOSTA has connectivity to all 3500 hosts/devices. now, i have to create a backup for HOSTA. and the back up is in another state. how do i get a list of all open ports on HOSTA so... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

8. Shell Programming and Scripting

bash script to test network connection - please help

I want to test if my host can connect to any of the following 10 hosts (192.168.1.0 to 192.168.1.9) I didnt know which command i should use, so i chose ping. (i wonder if i should use tracepath or sth else) my code is the following: #!/bin/bash clear firstPart="192.168.1" maxNum="9" ... (2 Replies)
Discussion started by: shadow_boi
2 Replies

9. Shell Programming and Scripting

Database Connection test in unix Script

i have a unix script that gives me the sysdate from the database EDNAMID.WORLD.What i want my script to do the following 1) Establish a database connection 2) if database connection is successfull then echo the message "Connected" 3) put the o/p of the Sql query in a spool file 4) then... (3 Replies)
Discussion started by: ali560045
3 Replies

10. Shell Programming and Scripting

How to Create a shell script to test the telnet connection status

Hi friends, I'm newbie to shell script. I wanted to create a shell script which able to write a result for all the telnet connection status. For example, from this machine I want to test the telnet connection (total 100+ servers) with this machine. Any idea how to write this shell script?... (16 Replies)
Discussion started by: yhcheong
16 Replies
Login or Register to Ask a Question