Electronic Mail
By using electronic mail, you can send messages, letters, and bio–data or any type of document to other users on the same system. We know that in the write command it is necessary that the recipient must be logged in and must not have refused message permission. As far as the mailing is concerned, it is not necessary that the recipient must be logged in. The mail sends messages to each other such that the messages get collected in a ‘mailbox’ somewhere in the system.
The user can see his terminal until he issues the necessary command to read it. Now there are two possibilities either the user is logged in or not. If the user is logged in then the system informs recipient of waiting mail at two different times:
First at the time when mail arrives while the recipient is busy in using UNIX commands. After finishing his current activity, he gets the following message immediately
You have mail.
If at this time the recipient does not read the mail, the user will get the message
You have mail.
again and again at the time of login until he reads his mail.
If the user is not logged in then his mail is collected in system mailbox. Each user on a system is assigned a system mailbox. A user’s system mailbox is file located in the
/ usr / spool / mail
directory. Let the user name is user1, who is going to receive your mail messages. The system mailbox of user1 would be
/ usr / spool / mail / user1
All mail received from different resources is appended to this mailbox file. The system mailbox contains mail that a user has received but has not yet read, deleted or saved to a file.
Additionally, each user is assigned a personal mailbox. All the messages, which have been read but not deleted or saved, are placed in user’s personal mailbox. The personal mailbox of the user user1 is
/ usr / user1 / mbox
The UNIX system provides the mail command that handles the sending and receiving of electronic mail. The general format of the mail command is
$ mail username
where username is the user–id of recipient. Let you, user3, want to send a mail to user1 then use the mail command as:
$ mail user1
We all know that Education begins with life.
Each time we read,
A seed is sown for the future.
Ctrl – d$
Like write command, the Ctrl – d is used to inform that the message is completed. The mail program now takes your message and passes it to the specified user. Obviously if user1 is logged in, he immediately get the message
You have mail.
after completely his current activity. Similarly you can send the same mail to more than one user by typing
$ mail user1 user5 user7
We all know that Education begins with life.
Each time we read,
A seed is sown for the future.
Ctrl – d$
If you want to mail a document written by you, say report.txt, then enter the following command at the prompt:
$ mail user1 user5 user7 < report.txt
In this the document report.txt is sent to three users uer1, user5 and user7.
You can read the mail, if any, by simply typing the mail as:
If you have no mail then the message “No mail” is displayed. But if you have some mail then just type mail as:
after this a list of messages in your current mailbox would be displayed. This list is followed by the mailbox prompt (&) to indicate waiting for input. You can issue several commands at this prompt. You can type a ? to view these mailbox commands.
UNIX provides several mailbox commands to customize your mail. Some of them are as:
- n displays nth message, where n stands for the message number
- d deletes current message
- d n1 n2 n3 deletes specified messages
- u undo last delete message
- u n1 n2 n3 undo specified messages
- l n1 n2 n3 prints specified mail on line printer
- s n1 n2 n3 file appends the specified messages to the file for later use
- r sends a reply to current message sender
- r2 sends a reply to message number 2
- . displays the current message
- $ displays the last message
- + displays next message, if it exists
- Enter displays next message, if it exists
These commands will be effective until you quit the mailbox prompt (&) by typing q as:
& q
Next time when you invoke mail command you would need to retype these commands. If you do not want to retype these commands each time you invoke the mail command, then it is necessary to store these commands in .mailrc file. The functional behavior of .mailrc command is similar to .exrc file to the vi editor program.
The .mailrc file is a hidden file which is executed each time you invoke the mail command.
If you want to look at the contents of your personal mailbox then invoke the mail command as:
$ mail –f
After this, your mailbox starts displaying the messages. If you have stored the mail in some other file, say myfile, then type
$ mail –f myfile
If you want to display the oldest message first then enter the following
$ mail –r
By default the latest mail is viewed first.
Lastly if some one tries to confuse you between the usage of write command and the mail command then do not worry. You can use write command to talk to the user directly if he is logged in and has not refused message permission. And if the user is not logged in then use the mail command to send messages.
Till now we have seen the write and mail commands which are invoked by the users. Now we will see those commands which are used by the superuser or system administrator only. Firstly we will see the wall command.
The wall Command
The wall command can be invoked by the superuser or system administrator only. The superuser can write to any terminal on the network by using the wall command. The wall command does not care that whether the terminals have written permissions to themselves or not.
It is the superuser who can compel you to read superuser messages. The superuser uses the wall command as:
# /etc/wall
Here note that the command prompt is # instead of $, in order to distinguish the superuser from normal users. Also note that you can not invoke the wall command as:
#wall
It is because here the system would search the current working directory first and then in the path specified. Since this file resides in a directory /etc, that’s why it is necessary to define the complete path as:
# /etc/wall
Let the super user wants to inform all the users that it is going to be shut down in 5 minutes, so please save their works as soon as possible. To achieve this the superuser uses the wall command as:
# /etc/wall
Hey, Wake Up.
The system is shutting down in 5 minutes.
Please save yoor work, if necessary.
Ctrl – d#
Like the write and mail commands, it is necessary to press Ctrl and d keys simultaneously to indicate that the message has been completed now.
Although you can also invoke the wall command at your terminal as:
$ /etc/wall
but unfortunately it would broadcast the message to nobody except yourself. Please try this command on your system and check the output.
The news Command
The news command is used to display the news made by the superuser or system administrator. The system administrator keeps different news in the different files in /usr/news directory. You can invoke these files as:
$ news
If you have three unread files, say sports, education and services, in news directory then
$ news
would display the contents of these files one by one on the monitor. The most recent news would be displayed first. You can also read a particular news file among several files. If you want to read education files then type
$ news education
Here once again the news is read by you, a file (.news_time of 0 bytes) is created in your home directory. The time of .news_time creation is used to find out when you have accessed the news. Now when you invoke the news command next time at dollar prompt ($), the UNIX system compares the time at at which the news item was posted and the creation of .news_time file.
If the news item has been posted before the creation .news_time file then it would not be displayed; otherwsie it would be displayed. To overcome this limitation, UNIX provides –a option as:
$ news –a
Now it would display all news items, whether current or not. The other options are as:
-n displays names of news item only, not their contents
-s reports the number of current news items
If you have read all the news items and try
$ news –s
then it promptly displays the message – “No news”.
The motd Command
The motd stands for ‘message of the day’. This command is also invoked by the superuser or the system administrator automatically when a user logs in. The motd program resides in /etc directory.
Reading the news depends on totally user’s choice. If you do not want to read news then there is no need to use news command. Opposite to this is the motd command. The motd command is executed automatically when a user logs in. As soon as you log in, the file /etc/profile gets executed automatically. This profile contains a command
cat /etc/motd
in it. The behavior of the /etc/profile is similar to Autoexec.bat file of DOS. The user has also his own .profile in his home directory in order to customize his working environment. When both these files exist then /etc/profile would be executed first and then .profile.