Automated handling of news and email is quite easy to implement in Linux.
First and foremost one should make a /usr/lib/ppp/ppp-on that initiates the ISP connection. Often, this file will simply contain the following:
Further specification will be performed in /etc/ppp/options:
connect "/usr/lib/ppp/chat -v -f /etc/ppp/chatscript" crtscts modem defaultroute asyncmap 00000000 user dirk /dev/modem 38400
To end a connection, use the supplied version of /usr/lib/ppp/ppp-off.
Having tested the functionality of these two scripts, one must then write scripts that perform the various tasks. The script to collect email has been described before, and we will here assume it is located at /home/dirk/pop.
A script for exchange of email can then be produced in /root/mail:
#! /bin/sh # # exchange mail # 10 minutes timeout: TIMEOUT=600 DT=10 # kick sendmail: sendmail -q & # retrieve mail: su dirk -c /home/dirk/pop # wait for sendmail to terminate: t=0 while ! mailq | grep -q "Mail queue is empty"; do t=$[$t+$DT] if [ $t -gt $TIMEOUT ] ; then echo "sendmail -q timeout ($TIMEOUT).." exit 1 fi sleep $DT done exit 0
The script to exchange news may be placed in /usr/lib/news/news:
A script to connect the various bits and pieces remains, and can be placed in /root/news+mail:
#!/bin/sh # # exchange news # must be run as news: cd /usr/lib/news #update the outgoing batch (C News): /usr/lib/newsbin/input/newsrun < /dev/null #exchange news: /usr/lib/newsbin/newsx acme news.acme.xz #and flush the incoming batch: /usr/lib/newsbin/input/newsrun < /dev/null
#!/bin/sh # # exchange news and email # must be run as root # if ! /usr/lib/ppp/ppp-on; then exit 1 fi trap "/usr/lib/ppp/ppp-off" 1 2 3 15 #exchange news+mail: /root/mail & su news -c ~news/news wait #disconnect.. /usr/lib/ppp/ppp-off #update the incoming batch (C News): su news -c /usr/lib/newsbin/input/newsrun < /dev/null & exit 0
It is quite easy to make an extension to the above that only will establish a connection if outgoing email and news is present. Lets call it /root/news+mail.cond, and keep in mind that the name of the outgoing news-spool must be updated to suit:
#!/bin/sh # # exchange news and email, only if outgoing news or mail # (C News spool) if [ -s /var/spool/news/out.going/acme/togo ] || ! ( mailq | grep -q "Mail queue is empty"); then /root/news+mail fi
The only thing remaining is to specify when all this is going to happen. This is done using the command
crontab -e as root. Let us assume that we always want to exchange news and mail at 07:00 in the morning, and after that every 4th hour assuming there are outgoing email and news:
Ensure that every component is tested well before you connect them together. One may later add several other tasks, such as adjustment of the time of day (using ntpdate), and automatic update (mirroring) of locally maintained WWW and FTP files up to the ISP (using make and ftp).
00 7 * * * /root/news+mail 00 11,15,19,23 * * * /root/news+mail.cond
ALT: Depending on ones preferences, it is also possible to turn the process upside down. Every time a PPP link is initiated, the script /etc/ppp/ip-up will be started. One may here add whatever magic is required to start exchange of email and news. See
man pppd for further detail.
ALT: It is also possible to automatically connect PPP whenever network traffic is detected. This is in many ways the more elegant solution, but it is quite dependent on a good configuration to avoid frequent (and costly) connections being made. More information can be found at:
diald utility is available from:
At the same location one will also find other variations on the theme PPP connections.