Solved

Port checking using the ksh shell

Posted on 2004-08-17
6
920 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

679 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