Depending on how your system is set up, you may notice that it
periodically says something like
You have new mail.
When you run your
the mail will be waiting for you in your mailbox.
You can also use this feature to check for changes
in several mailboxes, as well as changes in files and directories that don't
hold mail - more about that in a minute.
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:
set mail=(60 /usr/spool/mail/mikel)
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.
Many 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:
set mail=(/usr/spool/mail/mikel /usr/spool/mail/prodsupport)
When the list has more than one file, the shell will tell you which file
has changed with a message like
new mail in /usr/spool/mail/prodsupport.
All 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:
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
date, where the date
indicates when the report was created. Every report thus generates a
new file. In this case, you'd want to watch the log directory for the
creation of new files.
Here's another example. Let's say that you suspect someone is usingto 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:
set mail=(5 /usr/spool/uucp/.Log/uucico/somewhere)
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.
ls -ld /usr/local/logslrwxrwxrwx 1 root 15 Jul 10 1990 /usr/local/logs -> /foo/bar/logs %
ls -ld /foo/bar/logsdrwxrwxr-x 2 root 512 Aug 10 12:20 /foo/bar/logs %
Now, 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' files. To make them work in , 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.
NOTE: The next three features don't work on some Bourne shells.
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,
words, it will check after each command.
This may be slow on busy systems.
If MAILPATH is set, the shell will ignore the MAIL variable. You can't use both.
the Bourne shell prints
you have mail whenever any file that it's
watching changes. However,
if you follow a filename
in MAILPATH with a percent sign (
%) and a message,
the shell will print
the message whenever the file changes. For example, let's have the shell
you have mail when mail comes in and
New log! when a log file changes:
You can create a different message for every file that you care about.
Note that the Korn shell and bash use
? (a question mark)
instead of the
% before each message.
|21.7 Setting File Modification Time with touch||21.9 Keep File Printouts Up-to-Date Automatically with make|