macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Learning the Terminal in Jaguar, Part 2
Pages: 1, 2, 3

By default, the Mac OS X root home directory already contains a .forward file, but this one redirects mail not to another user, but into thin air. This happens because instead of an account name, root's .forward file contains the pathname /dev/null, which is the location of a Unix black hole. Streams of data directed to /dev/null, mail messages included, simply disappear. Since OS X's designers figure most users won't be accessing root's mail, they used this method to ensure mail doesn't pile up at the door while no one's home, eventually filling up your hard disk.



We only need, then, to edit root's .forward file. You've probably already noticed that there is no root directory in /Users -- so where is root's home? The easiest way to find any user's home directory is by using the finger command, which shows some basic information about the specified account. For root's, then:

[haru:~] chris% finger root
Login: root                     Name: System Administrator
Directory: /var/root            Shell: /bin/tcsh
Last login Fri Oct 11 19:46 (PDT) on console
No Plan.
[haru:~] chris%

And there beside Directory you'll see that root's home directory is /var/root.

As an alternative, you can always specify a user's home directory using the ~ shortcut along with the account name. Therefore, if you wanted to specify root's home directory, you would use ~root.

Let's have a look inside ~root:

[haru:~] chris% sudo ls /var/root
.CFUserTextEncoding .forward     .nsmbrc      Library

First, here are a couple of points about this command line:

  • Unlike the directories in /Users, ~root can only be browsed by root. Therefore, using sudo is necessary.
  • You see several items with names beginning with .. That initial dot is the Unix way of marking filenames as invisible to the shell (and to the Finder as well). You can see them, though, because you're running ls as root, and lsshows everything to root by default. If you were running ls as a regular user, however, you would need to use its -a flag to see those "dot files." For example, compare the output of these two commands: ls -a ~ and ls ~ (they should display the contents of your own home directory with, and without dot files.)

In any case, you should now see ~root/.forward, so let's next edit it with pico, using sudo since it's a root-owned file:

sudo pico /var/root/.forward

You should then see something like this:

Screen shot.

That single line, then, is the entire content of /var/root/.forward. To change it, first delete the file's single line by pressing control + K. Next, type in your account name (the name that's just before the "%" in the prompt; "chris" in this case):

Screen shot.

Save the file and close pico as usual, and you're done with the .forward file.

Now that everything is in place, you can perform a test. Send a new mail message to root:

[haru:~] chris% mail root
Subject: Test 2
This is only a test, again.
.
EOT
[haru:~] chris%

Check your mail, and you should see the new message, forwarded to you from root:

haru:~] chris% mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/mail/chris": 1 message 1 new
>N  1 chris          Wed Jan 22 08:56  13/406   "Test 2"
& 
Message 1:
From root  Wed Jan 22 08:56:20 2003
Date: Wed, 22 Jan 2003 08:56:20 -0800 (PST)
From: Chris Stone <chris>
To: root
Subject: Test 2

This is only a test, again.

& q
Saved 1 message in mbox
[haru:~] chris%

Here are a couple of more pointers for using mail:

  • If you have several messages listed, just enter the message number to have that message displayed.
  • Once a message has been displayed, it no longer shows up in the initial new mail list, but is saved in the file ~/mbox. You can safely delete that file if you don't want the messages saved. If you do keep the file and want to view the messages, however, just run mail with its -f flag, which will list all of your saved messages.

For the final test, go ahead and run the daily maintenance job manually by entering this command:

sudo periodic daily

Once a prompt has returned, the job is done and you can check your mail once more:

[haru:~] chris% sudo periodic daily
Password:
[haru:~] chris% mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/mail/chris": 1 message 1 new
>N  1 chris       Wed Jan 22 09:08  59/2244  "Haru.local"

If you take a look at the message, the beginning of it should look something like this:

Message 1:
From root  Wed Jan 22 09:08:54 2003
Date: Wed, 22 Jan 2003 09:08:54 -0800 (PST)
From: Chris Stone <chris>
To: root
Subject: Haru.local daily run output

Subject: Haru.local daily run output

Removing scratch and junk files:
rm: ./Mount01: is a directory
rm: ./Mount02: is a directory
rm: ./Mount03: is a directory
rm: ./Mount04: is a directory
rm: ./vi.recover: is a directory
rm: ./zBooterMnt: is a directory

Backing up NetInfo data

Checking subsystem status:

disks:
Filesystem   1K-blocks     Used    Avail Capacity  Mounted on
/dev/disk0s9  19532400 13471036  5866040    69%    /
fdesc                1        1        0   100%    /dev

Now that these regular reports will be coming in, you'll probably want to be able to understand them. In Part 3, you'll get a closer look at the scripts themselves to learn how to read the reports they generate. Until then, keep checking to see that you're receiving the reports as expected, and always feel free to submit your comments or questions to our TalkBack section.

Chris Stone is a Senior Macintosh Systems Administrator for O'Reilly, coauthor of Mac OS X in a Nutshell and contributing author to Mac OS X: The Missing Manual, which provides over 40 pages about the Mac OS X Terminal.


Read more Learning the Mac OS X Terminal columns.

Return to the Mac DevCenter.