This is the script that I use; I have put it in /usr/local/etc/poll.mail:
This is what the script does:#! /bin/bash # Poll for mail # May be run either by cron or at will by the superuser. PATH=/bin:/usr/bin:/etc:/sbin:/usr/sbin:/usr/local/bin # See if we already have PPP running if netstat -nr | grep ppp0 >/dev/null then echo PPP already running ppp_running=TRUE else # if not, start it up... if [ -f /var/run/diald.pid ] && ps -p `cat /var/run/diald.pid` then echo diald is running ping -c 1 mail.enterprise.net ppp_running=TRUE else ppp_running=FALSE ppp-on fi sleep 2 waitpd=0 until netstat -nr | grep ppp0 >/dev/null do if ps -axu | grep -v grep | grep -E 'pppd|diald' >/dev/null then sleep 5 waitpd=`expr $waitpd + 5` if [ $waitpd -gt 120 ] then echo Timed out exit 2 fi else echo PPP session was not established exit 1 fi done fi sleep 5 # Collect any mail that is waiting for us echo "Calling for mail for lfix.co.uk" fetchmail -aF -f /root/.fetchmail1rc case $? in 0) :;; # no problem 1) echo No mail to collect;; 2) echo Could not open socket;; 3) echo User authentication failed;; 4) echo Fatal protocol error;; 5) echo syntax error in fetchmail command;; 6) echo Bad permissions for run control file;; 7) echo Server error reported;; 8) echo Exclusion error;; 9) echo SMTP failure;; 10) echo Undefined error \(bug in fetchmail\);; *) echo Totally unexpected error in fetchmail;; esac echo "Calling for mail for Oliver.Elphick@lfix.co.uk" fetchmail -aF case $? in 0) :;; # no problem 1) echo No mail to collect;; 2) echo Could not open socket;; 3) echo User authentication failed;; 4) echo Fatal protocol error;; 5) echo syntax error in fetchmail command;; 6) echo Bad permissions for run control file;; 7) echo Server error reported;; 8) echo Exclusion error;; 9) echo SMTP failure;; 10) echo Undefined error \(bug in fetchmail\);; *) echo Totally unexpected error in fetchmail;; esac # Send anything we have for the outside world sendmail -q # Get news /usr/local/bin/slurp news.enterprise.net # If we started PPP, stop it again if [ "$ppp_running" = FALSE ] then ppp-off fi
Once you have created the script, make it executable by the command
# chmod 744 /usr/local/etc/poll.mailand then set up a crontab entry to run it automatically.