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.

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 "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.

"Alternative
Name Mode of Operation
hoststat "hoststat (V8.8 and Above)" Print persistent host status (V8.8 and above)
mailq "mailq" Print the queue contents
newaliases "newaliases" Rebuild the aliases file
purgestat "purgestat (V8.8 and Above)" Purge persistent host status (V8.8 and above)
smtpd "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 "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.

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 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:

To illustrate, consider this output:

------- Hostname -------- How long ago -----Results----- there.ufoa.edu 00:00:51 250 PAA27153 Message acce *tutorials.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 tutorials.ora.com were successful. The status for tutorials.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.

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 "Printing the Queue").

Note that the location of the queue is set with the QueueDirectory (Q) option (see 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).

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 "Rebuild the Alias Database"). In this mode the -v command-line switch (see -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 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).

purgestat (V8.8 and Above)

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

smtpd

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