#!/usr/bin/perl # This is script will connect to your isp (if not already connected), # send any outgoing mail and retrieve any incoming mail. If this # program made the connection, it will also break the connection # when it is done. # # Bill Adams # bill@evil.inetarena.com # # Revision History # 1.0.1 05 Sep 1998 baa Massive updates to work with fetchmail. # # Get the latest version from my home-page: # http://www.inetarena.com/~badams/computerstuff.html # following the 'Stuff I Have Written' link. # # License: GNU, but tell me of any improvements or changes. # use strict; my $suck; my $rdate; my ($my_syslog, $debug, $verbose); my $start_time = time; my $mailhost = 'mail'; my $sendmail_queue_dir = '/var/spool/mqueue/'; #Need trailing slash! my $interface = 'ppp0'; #Watch this interface my $max_tries = 1; #How many times to try and re-dial my $retry_delay = 300; #How long to wait to retry (in seconds) my $connect_timeout = 45; #How long to wait for connection #For the log file, be sure to put the >, >>, or | depending on # what you want it to do. I have also written a little program # called simple_syslog that you can pipe the data to. my $log_file = '>/dev/null'; #Where to put the data. $log_file = '>>/var/log/mailqueue.pl'; #$log_file = '>/dev/console'; my $this_hour = +[localtime()]->[2]; #Define this to get mail between midnight and 5 am #$suck = '/var/spool/suck/get.news.inn'; #Define this to set the time to a remote server #$rdate = '/usr/bin/rdate -s clock1.unc.edu'; #Where are the programs are located. You can specify the full path if needed. my $pppd = 'pppd'; my $fetchmail = 'fetchmail'; #'etrn.pl'; my $sendmail = 'sendmail'; #Where is the etrn/fetchmail pid my $fetchmail_pid = '/var/run/fetchmail.pid'; #Set the path to where we think everything will live. $ENV{'PATH'} = ":/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:"; my $lockfile = "/var/run/mailqueue.lock"; #lockfile for this program my $space = ' '; #Never know when you might need space my $program_name = $0; $program_name = substr ($program_name, (rindex ($program_name, '/') + 1)); open SYSLOG, $log_file or die "Could not open $log_file\n\t"; sys_log ("Started by UID $<"); #$< = 0; #suid root #Other global vars my $pppd_pid; #Make sure we are root. This has to be the case for everything # to work properly. if ($< != 0) { sys_log ("Not root...exit"); print STDERR "You are not root...sorry cannot run.\n"; exit (1); } sub sys_log { #Writes a message to the log file. my ($message) = @_; print SYSLOG join(' ', $program_name, ''.localtime(), #The '' puts it in a scaler context. $message)."\n"; print STDERR $message, "\n" if $debug; } #Get the command line args. $verbose = 1; for (my $i = 0; $i <= $#ARGV; $i++) { if ($ARGV[$i] eq '-v' || $ARGV[$i] eq '-verbose') { $verbose++; print "Running in verbose mode level ($verbose).\n"; } elsif ($ARGV[$i] eq '-d' || $ARGV[$i] eq '-debug') { $debug++; $verbose = 10; #Some high value so everything gets printed print STDERR "Running in debug mode.\n"; } elsif ($ARGV[$i] eq '-q' || $ARGV[$i] eq '-quiet') { $debug = 0; $verbose = 0; } elsif ($ARGV[$i] eq '-max_tries') { if (not defined $ARGV[$i + 1]) { printf STDERR "$0: Error: option -max_tries requires a value.\n"; &usage; } else { $max_tries = $ARGV[$i + 1]; } } elsif ($ARGV[$i] eq '-retry_delay') { if (not defined $ARGV[$i + 1]) { printf STDERR "$0: Error: option -retry_delay requires a value.\n"; &usage; } else { $max_tries = $ARGV[$i + 1]; } } elsif ($ARGV[$i] eq '-interface') { if (not defined $ARGV[$i + 1]) { printf STDERR "$0: Error: option -interface requires a value.\n"; &usage; } else { $max_tries = $ARGV[$i + 1]; } } elsif ($ARGV[$i] eq '-mailhost') { if (not defined $ARGV[$i + 1]) { printf STDERR "$0: Error: option -mailhost requires a value.\n"; &usage; } else { $mailhost = $ARGV[$i + 1]; } } else { print STDERR "Unknown command line option: [". $ARGV[$i]."]\n"; &usage; } } $| = 1 if $verbose; #Output un-buffered if we are verbose #Do some checking for programs &check_program ($my_syslog) || die "$0 -> Error: $my_syslog is required\n"; ($fetchmail = &check_program ($fetchmail)) || die "$0 -> Error: Could not find fetchmail/etrn\n"; ($pppd = &check_program ($pppd)) || die "$0 -> Error: Could not find pppd\n"; (-d $sendmail_queue_dir) || die "$0 -> Error: The sendmail queue directory\n\t[$sendmail_queue_dir] does not exist or is not a directory.\n"; ($sendmail = &check_program ($sendmail)) || die "$0 -> Error: Could not find $sendmail\n"; #Do some process locking. This kills any already running processes. if (-s $lockfile) { my $pid = `cat $lockfile`; chop $pid; if (not &process_is_dead ($pid)) { print STDERR "$0 -> Process locked by pid $pid killing it.\n" if $verbose; kill 15, $pid; waitpid ($pid, 0); #This has no effect. } sys_log
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content=""/>
<meta name="keywords" content=""/> 
<title>Fetchmail's Test List</title>
</head>
<body>
<table width="100%" cellpadding=0 summary="Canned page header"><tr>
<td width="30%">Back to <a href="/index.html">Home Page</a>
<td width="30%" align=right>Wed Oct 15 18:43:10 EDT 2003
</tr></table>
<hr />
<h1>Fetchmail's Test List</h1>

<p>Here are the server types on my regression-test list:</p>

<table border=1 width=80% align</