Solved

Port checking using the ksh shell

Posted on 2004-08-17
6
906 Views
Last Modified: 2013-12-27
I am after checking ports using telnet in the ksh shell, i need to telnet into the relevant ip and port check if there is connectivity if not display an error.



Thanks for Your Help,
Mike
0
Comment
Question by:Slightly_Imperfect
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 63 total points
ID: 11821081
Which ports are you checking? all? Just a few?

You are going to have to issue the telnet, and pipe stderr somewhere, like
telnet $ip $port 2>$out

You may want this in a loop for your ports, if there are many and in a second loop if there are lots of ips

for ip in 10.10.0.1 10.0.0.2 10.0.0.2
do
for port in 20 21 22 25 80 110 443
cat /dev/null >/tmp/out
do
telnet $ip $port 2> /tmp/out
fail=`grep Unable /tmp/out`  #bit messey using a tmp file
if [[ -n $fail ]];then
echo "failed"
done
done

However, telnet may hang if it actually connects, so you might want to use kill / pkill to kill off any telnet spwned by this script running after a short time (say 1 second?)

 
0
 

Author Comment

by:Slightly_Imperfect
ID: 11821109
how would you add the kill part to the actual script ?



Thanks,
Mike
0
 
LVL 18

Expert Comment

by:liddler
ID: 11821295
something like
telnet $ip $port 2> /tmp/out &
sleep 1
pkill telnet

0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 62 total points
ID: 11826321
telnet isn't the best tool for this type of job.  You'd be better off with something like netcat or similar.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question