Operating System - HP-UX
1833610 Members
3615 Online
110062 Solutions
New Discussion

Re: telnet to mail server no interactive in automatic shell

 
SOLVED
Go to solution
Jairo Campana
Trusted Contributor

telnet to mail server no interactive in automatic shell

I've read many examples about using a shell script to test a mail server
> (sendmail, postfix, etc) such as:
> #!/bin/bash
> telnet 1.2.3.4 25 << _EOF_
> HELO abc.com
> <- smtp conversation here (mail from, rcpt to, data, etc)
> _EOF_
>
> When I execute it, I get:
> 220 xyz.com ESMTP Sendmail 8.11.6/8.11.6; Fri, 11 Oct 2002
> 19:59:20 -0400
> Connection closed by foreign host.
>
> I've tried many ways to do it but it doesn't work. I've read somewhere that
> "telnet is not interactive so it will not work". I know Perl is much better
> and gives more control, but I want to do it first en bash script just for
> fun :) Any suggestion?
legionx
4 REPLIES 4
Rick Garland
Honored Contributor

Re: telnet to mail server no interactive in automatic shell

If the service (telnet) and the port (25) is enabled to accept the connections, you should be able to interact with SMTP.

It may be set to deny logins outside of the SNMP services.

Jeff Schussele
Honored Contributor

Re: telnet to mail server no interactive in automatic shell

Hi Jairo,

Check the /etc/mail/sendmail.cf on that system.
Look for PrivacyOptions and IF it's set to "goaway" then almost all SMTP status queries are disallowed.
If it's needmailhelo then the system will insist on an HELO or EHLO before it will allow any mail commands.

Also sendmail is *very* picky about name resolution. Make sure both the server & client are resolvable both forward (by name) & reverse (by IP). Sendmail will shoot you down if you're not.

Rgds,
Jeff

PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
harry d brown jr
Honored Contributor
Solution

Re: telnet to mail server no interactive in automatic shell

can you do it MANUALLY??

If so, then the problem is your script.

Stuff like this should be done in perl.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=209253
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=696550


live free or die
harry d brown jr
Live Free or Die
Daryl Much
Frequent Advisor

Re: telnet to mail server no interactive in automatic shell

FWIW, here's how I do it via perl. I don't use telnet but setup a real smpt connection instead.

HTH,

Chuck Davis
#####

#!/usr/bin/perl -w

use Net::SMTP;

$usage =<
this script checks if an SMTP server is available on a server. run like this:

$0

script exits with 0 if SMTP is running, exits with 1 if SMTP not running.

EOF
;

if (@ARGV != 1)
{ print $usage;
exit;
}

$server = $ARGV[0];

if (Net::SMTP->new( $server, Timeout=>5))
{ print "SMTP on $server is UP\n";
exit 0
}
else
{ print "SMTP on $server is DOWN\n";
exit 1
}