- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Checking if telnet works
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2006 08:49 AM
тАО08-18-2006 08:49 AM
I need to check if telnet works
i.e.
telnet box1 # this works and gives meaningful output
telnet box2 # error, doesn't work, record different output
Problem is, once I get into the telnet program, it's interactive, and I would like to do it with a script.
Solved! Go to Solution.
- Tags:
- telnet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2006 09:12 AM
тАО08-18-2006 09:12 AM
SolutionProbably the easist method would be to download and install the Perl module, Net::Telnet. You get all the error checking for free without having to slug through stderr yourself.
Another approach would be to use expect but Net::Telnet is easier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2006 09:20 AM
тАО08-18-2006 09:20 AM
Re: Checking if telnet works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2006 10:06 AM
тАО08-18-2006 10:06 AM
Re: Checking if telnet works
Use it like this (and note that I am discarding stderr):
---------------------------------
#!/usr/bin/sh
typeset STAT -i STAT=0
typeset REMHOST="mickey"
checktelnet.pl ${REMHOST} 2>/dev/null
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Ok"
else
echo "Cannot connect to ${REHHOST}; status ${STAT}"
fi
exit ${STAT}
-------------------------------
You can treat the Perl script as a blackbox since all you really want to know is telnetd running on a given host.
You will probably need to install the Net::Telnet module. Get it from:
http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm
and the attached perl script, checktelnet.pl:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2006 10:08 AM
тАО08-18-2006 10:08 AM
Re: Checking if telnet works
Here's one approach:
# cat ./probe
#!/usr/bin/sh
typeset HOST=${1}
telnet ${HOST} 21 |&
sleep 3
read -p REPLY
read -p REPLY
print -p quit
ACTION=`echo ${REPLY}|cut -d" " -f1`
if [ "${ACTION}" != "Connected" ]; then
echo "${HOST} FAILED to connect"
else
echo "${HOST} reponded_ok!"
fi
exit 0
...Run as:
# ./probe somehostname
...OR: Add a driver loop to query multiples hosts. A simple file of hostnames (or IP addresses) serves as input in that case.
...The exact message(s) returned may vary.
...for a good, working host:
# ./probe goodhost
Connection closed by foreign host.
goodhost reponded_ok!
...for a non-working host:
# ./probe badhost
telnet: connect: A remote host refused an attempted connect operation.
./probe[7]: print: 0403-039 No query process for pipe.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 06:21 AM
тАО08-21-2006 06:21 AM
Re: Checking if telnet works
There doesn't appear to be an easy way of scripting this, short of using expect. I got expect installed and am contemplating scripting it, but from my experience with it, it's very tedious (much more than Perl or ksh) and you have to take care of all input possibilities to make the right decision in the 'if' statements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 06:31 AM
тАО08-21-2006 06:31 AM
Re: Checking if telnet works
Could be that telnet or inetd is nor running on the second box.
Some consoles don't accept telnet at all. The new ilo consoles I'm receiving now only work with ssh.
If you have physical access to the second box:
Make sure telnetd is enabled in inetd.conf
make sure inetd itself is running
tail -f /var/adm/syslog/syslog.log
Try your telnet, then try ssh.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 07:05 AM
тАО08-21-2006 07:05 AM
Re: Checking if telnet works
Are you sure you can ssh to a remote console server? I've never seen it done, and every time I tried, it has failed while telnet always worked. I've always assumed it was a built-in feature. If this is configurable, where does it get set?
- Tags:
- ssh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 10:01 AM
тАО08-21-2006 10:01 AM
Re: Checking if telnet works
and there should be an entry like(not commented):
telnet stream tcp6 nowait root /usr/lbin/telnetd telnetd
the master daemon inetd consults this file for many network services. do a more /etc/inetd.conf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2006 05:11 PM
тАО08-21-2006 05:11 PM
Re: Checking if telnet works
hope it helps!