21.8 The MAILCHECK and mail Variables Check More than Mail
Depending on how your system is set up, you may notice that it
periodically says something like 21.8.1 For C Shell UsersIf you use the C shell, this feature is controlled by the mail shell variable (usually set in your .cshrc file ( 2.3 ) ). The shell normally checks your mailbox every five minutes. However, you can set a different interval at the start of the list. For example, the command below tells the shell to check my mailbox every 60 seconds:
% Note that the exact filename depends upon how your mail system is set up. For example, many systems use /usr/mail instead of /usr/spool/mail . Checking for mail takes time and can delay your prompt on busy systems. Don't set a short interval unless you need to. 21.8.1.1 Multiple MailboxesMany users need to watch more than one mailbox. For example, I need to watch /usr/spool/mail/mikel ; but if I'm responsible for product support, and my company maintains a special mail ID for support questions, I might also want to watch /usr/spool/mail/prodsupport . To do this, we set the mail variable so that it's a list of important files and directories:
%
When the list has more than one file, the shell will tell you which file
has changed with a message like 21.8.1.2 Watching Other FilesAll mail is doing is looking to see whether or not the file has changed; it doesn't know that it's looking at a "mail" file. Therefore, you can use it to watch anything you want; your list can even include directories. For example, let's say that you're running a program that periodically writes to the file /home/los/mikel/radio/log.out . Then you can set mail as follows:
% 21.8.1.3 Watching Directories
Watching a directory is
the same as watching a file; you'll be notified whenever the directory
changes (whenever a file is
added or deleted in the directory). So let's modify our previous example
slightly; let's say that your reports are named
/home/los/mikel/radio/log/
% Here's another example. Let's say that you suspect someone is using UUCP ( 1.33 ) to send company secrets to a system named somewhere . You want to watch this systems's UUCP traffic very carefully. To do so, you can tell the shell to inform you whenever the logfile changes:
% We've told the shell to check the log every five seconds because, given that we suspect security problems, we want to get our reports immediately. If the directory you're watching is actually a symbolic link ( 18.4 ) to another directory, be sure to check the actual directory and not the link. The sl ( 18.8 ) script is handy for this - or you can use ls -ld ( 16.8 ) :
% 21.8.2 For Bourne Shell UsersNow, let's assume that you're a Bourne shell user, and go through everything once more. The Bourne shell uses three variables to control mail notification. (These are usually set in users' .profile ( 2.2 ) files. To make them work in subshells ( 38.4 ) , export ( 6.1 ) the variables.) We'll assume that you read the C shell description already given, and move a bit faster. First, if you want to check only one file or directory, set the variable MAIL accordingly.
$
By default, the Bourne shell checks every ten minutes. To check at some other interval, set the variable MAILCHECK to your new interval, in seconds: for example, the command below tells the shell to check every 55 seconds:
$
One useful trick: if you set
MAILCHECK
to 0, the shell will check
whenever it prints the "primary" prompt (by default, If you want to watch several files, use the MAILPATH variable. Its value must be a list of file or directory names, separated by colons. For example:
$ If MAILPATH is set, the shell will ignore the MAIL variable. You can't use both.
Normally,
the Bourne shell prints
$
You can create a different message for every file that you care about.
Note that the Korn shell and
bash
use - |
|