6 # THIS PROGRAM IS ITS OWN MANUAL PAGE. INSTALL IN man & bin.
9 # hardcoded constants, should work fine for BSD-based systems
12 $sockaddr = 'S n a4 x8';
14 # system requirements:
15 # must have 'hostname' program.
17 #############################################################################
18 # Copyright (c) 1996 John T. Beck <john@beck.org>
19 # All rights reserved.
21 # Redistribution and use in source and binary forms, with or without
22 # modification, are permitted provided that the following conditions
24 # 1. Redistributions of source code must retain the above copyright
25 # notice, this list of conditions and the following disclaimer.
26 # 2. Redistributions in binary form must reproduce the above copyright
27 # notice, this list of conditions and the following disclaimer in the
28 # documentation and/or other materials provided with the distribution.
29 # 3. All advertising materials mentioning features or use of this software
30 # must display the following acknowledgement:
31 # This product includes software developed by John T. Beck.
32 # 4. The name of John Beck may not be used to endorse or promote products
33 # derived from this software without specific prior written permission.
35 # THIS SOFTWARE IS PROVIDED BY JOHN T. BECK ``AS IS'' AND ANY EXPRESS OR
36 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
38 # IN NO EVENT SHALL JOHN T. BECK BE LIABLE FOR ANY DIRECT, INDIRECT,
39 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
40 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
44 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 # This copyright notice derived from material copyrighted by the Regents
47 # of the University of California.
49 # Contributions accepted.
50 #############################################################################
51 # Further disclaimer: the etrn.pl script was highly leveraged from the
52 # expn.pl script which is (C) 1993 David Muir Sharnoff.
53 #############################################################################
59 $0 = "$av0 - running hostname";
60 chop($name = `hostname || uname -n`);
62 $0 = "$av0 - lookup host FQDN and IP addr";
63 ($hostname,$aliases,$type,$len,$thisaddr) = gethostbyname($name);
65 $0 = "$av0 - parsing args";
66 $usage = "Usage: $av0 [-wd] host [args]";
70 $server = shift(@ARGV);
72 die $usage unless $server;
76 push(@hosts,$hostname);
78 $0 = "$av0 - parsing sendmail.cf";
79 open(CF, "</etc/sendmail.cf") || die "open /etc/sendmail.cf: $!";
81 if (/^Fw.*$/){ # look for a line starting with "Fw"
85 $cwfile =~ s,^Fw[^/]*,,; # extract the file name
88 push (@cwfiles, $cwfile);
90 die "$cwfile is not readable" unless $optional;
93 if (/^Cw(.*)$/){ # look for a line starting with "Cw"
94 @cws = split (' ', $1);
96 $thishost = shift(@cws);
97 push(@hosts, $thishost) unless $thishost =~ "$hostname|localhost";
103 for $cwfile (@cwfiles) {
104 $0 = "$av0 - reading $cwfile";
105 if (open(CW, "<$cwfile")){
110 push(@hosts, $thishost) unless $thishost =~ $hostname;
114 die "open $cwfile: $!";
119 $0 = "$av0 - building local socket";
120 ($name,$aliases,$proto) = getprotobyname('tcp');
121 ($name,$aliases,$port) = getservbyname($port,'tcp')
122 unless $port =~ /^\d+/;
125 $0 = "$av0 - gethostbyname($server)";
127 ($name,$aliases,$type,$len,$thataddr) = gethostbyname($server);
130 $0 = "$av0 - socket to $server";
131 $that = pack($sockaddr, &AF_INET, $port, $thataddr);
132 socket(S, &AF_INET, &SOCK_STREAM, $proto)
134 $0 = "$av0 - connect to $server";
135 print "debug = $debug server = $server\n" if $debug > 8;
136 if (! connect(S, $that)) {
137 $0 = "$av0 - $server: could not connect: $!\n";
139 select((select(S),$| = 1)[0]); # don't buffer output to S
142 $0 = "$av0 - talking to $server";
143 &alarm("greeting with $server",'');
147 if (/^(\d+)([- ])/) {
149 $0 = "$av0 - bad numeric response from $server";
150 &alarm("giving up after bad response from $server",'');
151 &read_response($2,$watch);
153 print STDERR "$server: NOT 220 greeting: $_"
154 if ($debug || $watch);
158 $0 = "$av0 - bad response from $server";
159 print STDERR "$server: NOT 220 greeting: $_"
160 if ($debug || $watch);
163 &alarm("greeting with $server",'');
167 # if this causes problems, remove it
168 $0 = "$av0 - sending helo to $server";
169 &alarm("sending ehlo to $server","");
170 &ps("ehlo $hostname");
173 if (/^250([- ])ETRN(.+)$/){
182 print "ETRN supported\n" if ($debug);
183 &alarm("sending etrn to $server",'');
185 $server = shift(@hosts);
194 print "\nETRN not supported\n\n"
197 &alarm("sending 'quit' to $server",'');
198 $0 = "$av0 - sending 'quit' to $server";
210 # print to the server (also to stdout, if -w)
214 print ">>> $p\n" if $watch;
220 local($alarm_action,$alarm_redirect,$alarm_user) = @_;
222 $SIG{ALRM} = 'handle_alarm';
227 &giveup($alarm_redirect,"Timed out during $alarm_action",$alarm_user);
230 # read the rest of the current smtp daemon's response (and toss it away)
233 local($done,$watch) = @_;
236 while(($done eq "-") && ($s = <S>) && ($s =~ /^\d+([- ])/)) {
248 ################### BEGIN PERL/TROFF TRANSITION
255 .\" ############## END PERL/TROFF TRANSITION
256 .TH ETRN 1 "January 25, 1997"
259 etrn \- start mail queue run
270 command to start mail delivery from the host given on the command line.
274 for each host the local sendmail accepts e-mail for, but if
278 uses these as arguments for the SMTP
280 commands passed to the host given on the command line.
283 The normal mode of operation for
285 is to do all of its work silently.
286 The following options make it more verbose.
287 It is not necessary to make it verbose to see what it is
288 doing because as it works, it changes its
290 variable to reflect its current activity.
293 watch, flag will cause
295 to show you its conversations with the mail daemons.
298 debug, flag will expose many of the inner workings so that
299 it is possible to eliminate bugs.
301 No enviroment variables are used.
308 Not all mail daemons will implement
311 It is assumed that you are running domain names.
313 Leveraged from David Muir Sharnoff's expn.pl script.
314 Christian von Roques added support for
316 and fixed a couple of bugs.
318 The latest version of
320 is available in the contrib directory of the sendmail
321 distribution through anonymous ftp at
322 .IR ftp://ftp.sendmail.org/ucb/src/sendmail/ .
324 .I John T. Beck\ \ \ \ <john@beck.org>