Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Port checking using the ksh shell

Posted on 2004-08-17
6
Medium Priority
?
962 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 252 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 248 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses

618 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