Linux Network Administratoramp;#039;s Guide (3rd Edition) [Electronic resources]

Tony Bautts, Terry Dawson, Gregor N. Purdy

نسخه متنی -صفحه : 121/ 95
نمايش فراداده

12.8. Tips and Tricks

There are a number of things you can do to make managing a sendmail site efficient. A number of management tools are provided in the sendmail package; let's look at the most important of these.

12.8.1. Managing the Mail Spool

Mail is queued in the /var/spool/mqueue directory before being transmitted. This directory is called the mail spool. The sendmail program provides the mailq command as a means of displaying a formatted list of all spooled mail messages and their status. The /usr/bin/mailq command is a symbolic link to the sendmail executable and behaves identically to:

# sendmail -bp

The output of the mailq command displays the message ID, its size, the time it was placed in the queue, who sent it, and a message indicating its current status. The following example shows a mail message stuck in the queue with a problem:

$ mailq
Mail Queue (1 request)
--Q-ID-- --Size-- -----Q-Time----- ------------Sender/Recipient------------
RAA00275      124 Wed Dec  9 17:47 root
(host map: lookup (tao.linux.org.au): deferred)
terry@tao.linux.org.au

This message is still in the mail queue because the destination host IP address could not be resolved.

To force sendmail to immediately process the queue, issue the /usr/bin/runq command. sendmail will process the mail queue in the background. The runq command produces no output, but a subsequent mailq command will tell you if the queue is clear.

12.8.2. Forcing a Remote Host to Process Its Mail Queue

If you use a temporary dial-up Internet connection with a fixed IP address and rely on an MX host to collect your mail while you are disconnected, you will find it useful to force the MX host to process its mail queue soon after you establish your connection.

A small perl program is included with the sendmail distribution that makes this simple for mail hosts that support it. The etrn script has much the same effect on a remote host as the runq command has on the local server. If we invoke the command as shown in this example:

# etrn vstout.vbrew.com

we force the host vstout.vbrew.com to process any mail queued for our local machine.

Typically you'd add this command to your PPP startup script so that it is executed soon after your network connection is established.

12.8.3. Mail Statistics

sendmail collects data on the volume of mail traffic and some information on the hosts to which it has delivered mail. There are two commands available to display this information, mailstats and hoststat.

12.8.3.1 mailstats

The mailstats command displays statistics on the volume of mail processed by sendmail. The time at which data collection commenced is printed first, followed by a table with one row for each configured mailer and one showing a summary total of all mail. Each line presents eight items of information, which are described in Table 12-5.

Table 12-5. The fields displayed by mailstat

Field

Meaning

M

The mailer (transport protocol) number

msgsfr

The number of messages received from the mailer

bytes_from

The Kbytes of mail from the mailer

msgsto

The number of messages sent to the mailer

bytes_to

The Kbytes of mail sent to the mailer

msgsreg

The number of messages rejected

msgsdis

The number of messages discarded

Mailer

The name of the mailer

A sample of the output of the mailstats command is shown in Example 12-7.

Example 12-7. Sample output of the mailstats command
# /usr/sbin/mailstats
Statistics from Sun Dec 20 22:47:02 1998
M   msgsfr  bytes_from   msgsto    bytes_to  msgsrej msgsdis  Mailer
0        0          0K       19        515K        0       0  prog
3       33        545K        0          0K        0       0  local
5       88        972K      139       1018K        0       0  esmtp
=  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  
=  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  
T      121       1517K      158       1533K        0       0

This data is collected if the StatusFile option is enabled in the sendmail.cf file and the status file exists. The StatusFile option is defined in the generic Linux configuration and therefore defined in the vstout.cf file we built from the generic configuration, as shown below:

$ grep StatusFile vstout.cf
O StatusFile=/etc/mail/statistics

To restart the statistics collection, make the statistics file zero length and restart sendmail.

12.8.3.2 hoststat

The hoststat command displays information about the status of hosts to which sendmail has attempted to deliver mail. The hoststat command is equivalent to invoking sendmail as:

sendmail -bh

The output presents each host on a line of its own, and for each the time since delivery was attempted to it, and the status message received at that time.

Persistent host status is maintained only if a path for the status directory is defined by the HostStatusDirectory option, which in turn is defined in the m4 macro configuration file by confHOST_STATUS_DIRECTORY. By default, no path is defined for the host status directory and no persistent host status is maintained.

Example 12-8 shows the sort of output you can expect from the hoststat command. Note that most of the results indicate successful delivery. The result for earthlink.net, on the other hand, indicates that delivery was unsuccessful. The status message can sometimes help determine the cause of the failure. In this case, the connection timed out, probably because the host was down or unreachable at the time delivery was attempted.

Example 12-8. Sample Output of the hoststat Command
# hoststat
-------------- Hostname ---------- How long ago ---------Results---------
mail.telstra.com.au                    04:05:41 250 Message accepted for
scooter.eye-net.com.au              81+08:32:42 250 OK id=0zTGai-0008S9-0
yarrina.connect.com.a               53+10:46:03 250 LAA09163 Message acce
happy.optus.com.au                  55+03:34:40 250 Mail accepted
mail.zip.com.au                        04:05:33 250 RAA23904 Message acce
kwanon.research.canon.com.au        44+04:39:10 250 ok 911542267 qp 21186
linux.org.au                        83+10:04:11 250 IAA31139 Message acce
albert.aapra.org.au                    00:00:12 250 VAA21968 Message acce
field.medicine.adelaide.edu.au      53+10:46:03 250 ok 910742814 qp 721
copper.fuller.net                   65+12:38:00 250 OAA14470 Message acce
amsat.org                            5+06:49:21 250 UAA07526 Message acce
mail.acm.org                        53+10:46:17 250 TAA25012 Message acce
extmail.bigpond.com                 11+04:06:20 250 ok
earthlink.net                       45+05:41:09 Deferred: Connection time

The purgestat command flushes the collected host data and is equivalent to invoking sendmail as:

# sendmail -bH

The statistics will continue to grow until you purge them. You might want to periodically run the purgestat command to make it easier to search and find recent entries, especially if you have a busy site. You could put the command into a crontab file so it runs automatically, or just do it yourself occasionally.