LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what is effect of mail command (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-effect-of-mail-command-776084/)

sumeet inani 12-16-2009 08:59 AM

what is effect of mail command
 
my OS has two users root & lxuser.If I become root in terminal and run 'mail lxuser'(without quotes ofcourse).then how will lxuser come to know of mail.

XavierP 12-16-2009 09:04 AM

Every user has a folder in /var/mail (so /var/mail/root, /var/mail/usera, /var/mail/userb and so on), so they could check there.

sumeet inani 12-16-2009 09:29 AM

Does that mean in my example lxuser has to check in /var/mail/lxuser & will not be notified in any way like during login or on X GUI?

pcunix 12-16-2009 09:53 AM

Bash can check. From "man bash":

MAILCHECK
Specifies how often (in seconds) bash checks for mail. The
default is 60 seconds. When it is time to check for mail, the
shell does so before displaying the primary prompt. If this
variable is unset, or set to a value that is not a number
greater than or equal to zero, the shell disables mail checking.
MAILPATH
A colon-separated list of file names to be checked for mail.
The message to be printed when mail arrives in a particular file
may be specified by separating the file name from the message
with a `?'. When used in the text of the message, $_ expands to
the name of the current mailfile. Example:
MAILPATH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has
mail!"'
Bash supplies a default value for this variable, but the loca-
tion of the user mail files that it uses is system dependent
(e.g., /var/mail/$USER).

sumeet inani 12-17-2009 01:49 AM

I became root in terminal using 'su'(without quotes obviously)
Then I mailed user 'abhiluv' as follows
#mail abhiluv
Subject: hi
what is going on ? <pressed ctrl+d>
Cc: root
#ls -aps /var/mail
8 ./ 8 ../ 0 abhiluv 4 cdot 8 root 4 rpc

Why my mail did not appear ?

aneeshk_k 12-17-2009 02:02 AM

Sumeet, the mail should be there in the file /var/mail/abhiluv. You can view that either by using the command "cat /var/mail/abhiluv" or by entering the command "mail" from abhiluv's shell.

Eg:

[abhiluv@localhost ~]$ mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/abhiluv": 1 message
> 1 root Thu Dec 17 13:29 21/746 "hi"
&

Entering "1" will display the first e-mail for abhiluv.

If you prefer you can use other email clients like "pine" for viewing the e-mails.

sumeet inani 12-17-2009 02:06 AM

As shown above size of abhiluv is 0 bytes but still as 'aneeshk_k' says I tried
Code:

$mail
No mail for abhiluv

I think cc means to send a copy so as you must have seen I sent even to root.

Code:

#whoami
root
#mail
No mail for abhiluv

Why does this happen ?
Don't you think it should be 'no mail for root'?

sumeet inani 12-17-2009 02:25 AM

in ubuntu 9.04 I installed
#apt-get install mailutils
Then I send mail to lxuser as root and it worked.
But why does it not happen RHEL 5.3
I have noticed that in both OS echo $MAILPATH returned nothing
so can't find mistake in RHEL 5.3 ?

pcunix 12-17-2009 05:58 AM

Quote:

Originally Posted by sumeet inani (Post 3794946)
in ubuntu 9.04 I installed
#apt-get install mailutils
Then I send mail to lxuser as root and it worked.
But why does it not happen RHEL 5.3
I have noticed that in both OS echo $MAILPATH returned nothing
so can't find mistake in RHEL 5.3 ?

So set it yourself in .bash_profile

sumeet inani 12-18-2009 12:54 AM

I think I will have to append following line in ~/.bash_profile

MAILPATH=$MAILPATH:/var/mail/lxuser?"lxuser got mail"

Am i right?
I noticed that if I open terminal then message will come only after I run some command(like ls or anything)not by itself automatically.Can we colour the message so noticeable?
Or should I be contented to run 'mail' like we check in our yahoo,gmail etc. accounts with web browser

pcunix 12-18-2009 03:08 AM

That's the way it works in Bash. The reason is that it doesn't want to interrupt you mid-command.

I keep looking for another easy way to monitor a changing file or directory. It seems to me that there ought to be some command line thing, but if there is, I don't know of it.

While we're waiting for someone to point out what I missed, take a look at http://aplawrence.com/Unixart/watchdir.html

That has links for dnotify, inotify, changedfiles, watch, Gamin and fam. None of those directly do what you want, but any of them could be used to roll up something.

sumeet inani 12-19-2009 03:27 AM

correction
 
Quote:

Originally Posted by XavierP (Post 3793748)
Every user has a folder in /var/mail (so /var/mail/root, /var/mail/usera, /var/mail/userb and so on), so they could check there.

small mistake I found that there is a file named /var/mail/<username>.


All times are GMT -5. The time now is 07:39 PM.