LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Automated telnet for testing servers (https://www.linuxquestions.org/questions/linux-general-1/automated-telnet-for-testing-servers-749010/)

jcllings 08-20-2009 08:20 AM

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.

centosboy 08-20-2009 09:38 AM

Quote:

Originally Posted by jcllings (Post 3650836)
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.

jcllings 08-20-2009 10:38 AM

Quote:

Originally Posted by centosboy (Post 3650921)
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.

jcllings 08-20-2009 10:42 AM

Quote:

Originally Posted by centosboy (Post 3650921)
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.

chrism01 08-21-2009 02:09 AM

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.
:)


All times are GMT -5. The time now is 03:04 PM.