checking a connection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking a connection
# 1  
Old 08-17-2005
checking a connection

Hello,

Is it possible to check if a host is accepting connections on a particular port using a shell script? Can't we automate telnet to check for the same?

Thanks in advance
Azmath H Shaik
# 2  
Old 08-17-2005
Sure.
Code:
#!/bin/ksh
telnet yourhost 25 << EOF
^]
EOF
exit

I leave it to you to find how to check if it was successful. Just change the port to what you need - I didn't test to see if it would work with all the different ports.
# 3  
Old 08-20-2005
It works fine for all ports (atleast for me). I dump the output to a temporary file and do a grep for string "connected" to check if the connection was successful!
Thanks
# 4  
Old 08-20-2005
You don't need to dump the output and grepping on it.
You can only check the status of the "telnet" command :

Code:
#!/bin/ksh
telnet yourhost 25 << EOF
^]
EOF
if [[ $? -ne 0 ]] ; then
  Do what you need
fi

Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

2. SCO

Stop boot system at "Checking protected password and checking subsystem databases"

Hi, (i'm sorry for my english) I'm a problem on boot sco unix 5.0.5 open server. this stop at "Checking protected password and checking subsystem databases" (See this image ) I'm try this: 1) http://www.digipedia.pl/usenet/thread/50/37093/#post37094 2) SCO: SCO Unix - Server hangs... (9 Replies)
Discussion started by: buji
9 Replies

3. Shell Programming and Scripting

Script for checking firewall connection

Dear all I am writing a shell script to use telnet for the connection test There are 3 cases to test and detail as: /* Case 1 - The port can be connected */ # telnet host_a 20101 < /dev/null 2>&1 | grep -q Connected # echo $? return 0 /* Case 2 - The port cannot be connected */ #... (1 Reply)
Discussion started by: on9west
1 Replies

4. 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

5. UNIX for Advanced & Expert Users

Connection reset by peer..closing connection

Hello I'm facing the above problem while doing a performance run. I've a script which I'm launching from my windows desktop using mozilla. The script will invoke backend action on a Solaris host which in turn feeds the records to a driver located on a linux box(Cent OS). What's happening is... (1 Reply)
Discussion started by: subramanyab
1 Replies

6. UNIX for Dummies Questions & Answers

ssh_exchange_identification: Connection closed by remote host Connection closed

Hi Everyone, Good day. Scenario: 2 unix servers -- A (SunOS) and B (AIX) I have an ftp script to sftp 30 files from A to B which happen almost instantaneously i.e 30 sftp's happen at the same time. Some of these sftp's fail with the following error: ssh_exchange_identification: Connection... (1 Reply)
Discussion started by: jeevan_fimare
1 Replies

7. UNIX for Dummies Questions & Answers

checking for non-zero value

I have a process that spits out a file called sqlplus.out, here is what the result looks like: Currently the value you see is zero, what I need to do is perform an action if that value is non-zero, so how do I check that value in an if statement? If it helps at this moment in development the... (6 Replies)
Discussion started by: philplasma
6 Replies

8. IP Networking

checking a connection still exists?

Hi I have a bit of c code which I'm trying to use as a relay between apache and a scgi cluster. Example of problem code is below: while((n = recv(scgiSock, local_data, MAX_LENGTH, 0)) > 0) { time(&t2); time_now = t2 - t1; if(time_now > TIMEOUT) ... (2 Replies)
Discussion started by: fishman2001
2 Replies

9. UNIX for Dummies Questions & Answers

checking Processes

I have aix version 5.1 I was wondering how I can check all running processes? I have used several ps commands but have been unsuccessful at it. I can see all with {ps aux } I have a little trouble knowing what I am looking for also. I should be looking at length of time and processor usage? I am... (3 Replies)
Discussion started by: rocker40
3 Replies
Login or Register to Ask a Question