start page | rating of books | rating of authors | reviews | copyrights

sendmail

sendmailSearch this book
Previous: 35.10 Alphabetized Reference Chapter 36 Next: 36.2 Command-Line Switches
 

36. The Command Line

Contents:
Alternative argv[0] Names
Command-Line Switches
List of Recipient Addresses
Processing the Command Line
sendmail's exit() Status
Pitfalls
Alphabetized Reference

The initial behavior of sendmail is determined largely by the command line used to invoke it. The command line can, for example, cause sendmail to use a different configuration file or to rebuild the aliases file rather than deliver mail. The command line can be typed at your keyboard, executed from a boot-time script, or even executed by an MUA when sending mail.

The format of the sendmail command line is:



argv[0] switches recipients

Here, argv[0] is the name used to run sendmail . The switches , if any of them are present, must always precede the list of recipients. The recipients is a list of zero or more recipient address expressions.

36.1 Alternative argv[0] Names

The sendmail program may exist in any of several places, depending on the version of the operating system you are running. Usually, it is located in the /usr/lib directory and is called sendmail , [1] but it can alternatively be located in the /etc , /usr/sbin , or /usr/etc directory. The location of the sendmail program can be found by examining the /etc/rc files for BSD UNIX or the /etc/init.d files for Sys V UNIX (see Section 3.4, "Role as a Daemon" ).

[1] On Sun systems you will find /usr/lib/sendmail.mx for use with the Domain Name System.

In addition to the name sendmail , other names (in other directories) can exist that alter the behavior of sendmail . Those alternative names are usually symbolic links to /usr/lib/sendmail . On some systems they may be hard links, and in rare cases you may actually find them to be copies. The complete list of other names is shown in Table 36.1 .

Table 36.1: "Alternative
Name Mode of Operation
hoststat Section 36.1.1, "hoststat (V8.8 and Above)"

Print persistent host status (V8.8 and above)

mailq Section 36.1.2, "mailq"

Print the queue contents

newaliases Section 36.1.3, "newaliases"

Rebuild the aliases file

purgestat Section 36.1.4, "purgestat (V8.8 and Above)"

Purge persistent host status (V8.8 and above)

smtpd Section 36.1.5, "smtpd"

Run in daemon mode

When sendmail looks for the name under which it is running, it strips any leading directory components from argv[0] and compares the result (in a case-sensitive fashion) to its internal list of alternative names. If a match is found, its mode of operation is changed to conform to that of the alternative name. If no match is found (if, say, a link is named Mailq , note the uppercase M ), sendmail does not change its mode.

The name that is found is used to build an argument list for use with process listings. For example, if the name was sendmail.mx (from SunOS), a process listing produced with ps (3) would look something like this:

root  1247  620 p0 S  07:22 0:00 -AA15186 (sendmail.mx)

Here, the (sendmail.mx) shows that sendmail was run under the name sendmail.mx .

Note that sendmail uses the hard-coded name " sendmail " for logging purposes with syslog (3) (see Section 26.1.1, "syslog(3)" ). Therefore logged errors and warnings always appear to come from sendmail , no matter what name was used to run it.

As a final note, be aware that command-line switches are processed immediately after the name but before sendmail finalizes its mode of operation. Thus the use of particular switches can completely cancel any special meaning given a name.

36.1.1 hoststat (V8.8 and Above)

The hoststat command is a synonym for the -bh command-line switch. It causes sendmail to print its persistent host status and exit. Persistent host status is enabled with the HostStatusDirectory option (see Section 34.8.31, HostStatusDirectory ).

The output produced by this command begins with a heading like this:

------- Hostname -------- How long ago -----Results-----

Then for each host that has its status saved, sendmail prints this information:

Hostname

This is the name of the host that was connected to. It may not be the hostname specified for the recipient. It could easily be an MX record instead. If a message has multiple recipients, a separate status line will be produced for each unique host that is tried. If this name is prefixed with an asterisk, the status file is locked and currently being updated.

How long ago

This shows how long ago this status record was updated. It is printed in the form:

DD+HH:MM:SS

Here, DD is the number of days. If the status was updated less than a day ago, the DD+ is omitted. The HH is hours, the MM is minutes, and the SS is seconds. The colons are literal.

Results

This shows the result of the last connection attempt, failure, or success. If no reason was stored, this prints as:

No status available

If a result was stored, it will print in three parts:



smtp id msg

The smtp is the SMTP reply code. The msg is the text of the message generated by the other end or other program.

To illustrate, consider this output:

------- Hostname -------- How long ago -----Results-----  there.ufoa.edu                              00:00:51 250 PAA27153 Message acce *books.ora.com                               07:43:39 250 GAA01255 Message acce  prog.ammers.com                             06:55:08 No status available  fbi.dc.gov                                  03:28:53 Connection refused

Here, the previous connections to there.ufoa.edu and books.ora.com were successful. The status for books.ora.com is currently being updated, hence the asterisk showing it is locked. The host prog.ammers.com shows no status because connection to it could not be made. The last example show that the connection to fbi.dc.gov was refused by that host.

Note that the results are limited to 27 characters unless the -v command-line flag is also used. In that case, results are limited to 79 characters, thus providing more complete information.

36.1.2 mailq

The name mailq (a synonym for the -bp command-line switch) causes sendmail to print the contents of the mail queue and then exit (see Section 23.4, "Printing the Queue" ).

Note that the location of the queue is set with the QueueDirectory ( Q ) option (see Section 34.8.48, QueueDirectory (Q) ). That location can be overridden from the command line, but if it is, sendmail may give up its root privilege (unless it was run by root ).

36.1.3 newaliases

The name newaliases (a synonym for the -bi command-line switch) causes sendmail to rebuild the aliases database files, print summary information, and then immediately exit (see Section 24.5.1, "Rebuild the Alias Database" ). In this mode the -v command-line switch (see Section 36.7.41, -v ) is automatically implied, and sendmail runs in verbose mode.

The location of the aliases file is given in the configuration file with the AliasFile ( A ) option (see Section 34.8.1, AliasFile (A) ). That location can be overridden from the command line, but if it is, sendmail gives up its root privilege (unless it was run by root ).

36.1.4 purgestat (V8.8 and Above)

The name purgestat is a synonym for the V8.8 and above -bH command-line switch (see Section 36.7.6, -bH ). It causes sendmail to clear (purge) all the host-status information that was being saved under the HostStatusDirectory option's directory (see Section 34.8.31 ). Clearing is done by removing all the directories under the HostStatusDirectory directory. Note that the HostStatusDirectory directory is not itself removed.

36.1.5 smtpd

The name smtpd is a synonym for the -bd command-line switch (see Section 36.7.5, -bd ). It causes sendmail to run in the background as a daemon, listening for incoming SMTP mail (see Section 4.1.1, "Daemon Mode (-bd)" ). This mode of operating is usually combined with the -q command-line switch (see Section 23.6.1, "Periodically with -q" ), which causes sendmail to periodically process the queue.


Previous: 35.10 Alphabetized Reference sendmail Next: 36.2 Command-Line Switches
35.10 Alphabetized Reference Book Index 36.2 Command-Line Switches