LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-20-2009, 08:20 AM   #1
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Rep: Reputation: 15
Automated telnet for testing servers


So I have a script that is supposed to check to see if a mail server is up and responsive. What I want to know is how I can send it the telnet escape character. I've tried:

VAR=`(sleep 5;echo quit) | (telnet mailserver.timbuktu.net 25 2>&- )`

This works BUT there is a problem as the mail server may have been accidentally firewalled off. If this happens, my automated checking script will hang. What I want to do is send the escape character so that the '>' prompt comes up. They I should be able to send it "quit" even if it is hung on not getting a response from the server.

VAR=`(sleep 5;echo -e '^]';sleep 1;echo quit) | (telnet arhqmg01.usarec.army.mil 25 2>&- )`

The above doesn't work. telnet interprets CTRL+] as '^]' but you can't type '^]' and get the same effect. So I guess what I need is to send the actual keystrokes. Like echo "\somenumber" ; echo quit

Jim C.
 
Old 08-20-2009, 09:38 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by jcllings View Post
So I have a script that is supposed to check to see if a mail server is up and responsive. What I want to know is how I can send it the telnet escape character. I've tried:

VAR=`(sleep 5;echo quit) | (telnet mailserver.timbuktu.net 25 2>&- )`

This works BUT there is a problem as the mail server may have been accidentally firewalled off. If this happens, my automated checking script will hang. What I want to do is send the escape character so that the '>' prompt comes up. They I should be able to send it "quit" even if it is hung on not getting a response from the server.

VAR=`(sleep 5;echo -e '^]';sleep 1;echo quit) | (telnet arhqmg01.usarec.army.mil 25 2>&- )`

The above doesn't work. telnet interprets CTRL+] as '^]' but you can't type '^]' and get the same effect. So I guess what I need is to send the actual keystrokes. Like echo "\somenumber" ; echo quit

Jim C.
what kind of script is it>?
surely you can set a timeout variable
if the server does not respond in this given time, do something.
 
Old 08-20-2009, 10:38 AM   #3
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by centosboy View Post
what kind of script is it>?
surely you can set a timeout variable
if the server does not respond in this given time, do something.
I figured this one out. echo '\033\ ' because, for the Solaris version of telnet, the quit command is ^\. telnet doesn't mind the space at the end and it keeps the ' from being escaped.

Jim C.
 
Old 08-20-2009, 10:42 AM   #4
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by centosboy View Post
what kind of script is it>?
surely you can set a timeout variable
if the server does not respond in this given time, do something.
I forgot to mention. You can, of course, set a timeout environment variable but it was something I was avoiding because I might be throwing the commands in question over an SSH connection. The test has to be run from the perspective of the machine that needs access to the server in question.
 
Old 08-21-2009, 02:09 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Can I recommend you don't put emails in clear text like that, there are plenty of web bots that look for that and then your spam problem just gets worse.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automated testing tool for linux (ubuntu) tuux Linux - Software 3 08-08-2009 11:33 PM
Bash automated testing anonguy9 LinuxQuestions.org Member Success Stories 0 03-29-2009 06:13 PM
automated remote command execution using telnet sharad Linux - General 1 01-17-2007 12:59 AM
Automated Regression Testing Software qcoder Programming 3 04-21-2006 12:24 PM
Automated Telnet Login mbjunior99 Mandriva 3 04-13-2005 05:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration