I know you can use write
to send a message to a currently logged in user, but how do you leave a message for a user who is not logged in? The solution I have seen is modify the motd, but that will be displayed to all users. How can I leave a message for individual users to read when they login?
2 Answers 2
You can use the mail
command to send a message to user jdoe
like this:
mail -s "The subject goes here" jdoe
You will enter an interactive environment where you can type your message (mail body). Type Control-D
in the beginning of a line to end the message and send it (you will be asked for an optional CC recipient - just hit enter if you don't want one).
You can also do:
mail -s "The subject goes here" jdoe < textfile
or
echo "John, please don't forget our meeting" | mail -s "Reminder" jdoe
The next time jdoe logs in, he will receive a notification like "You have new mail" and he must type mail
to read it (perhaps this is a drawback if the user doesn't know he must do this).
-
This is exactly what I was looking for! Now is there a way to show how many new messages there are without opening
mail
? I'm reading the man page and I don't see a way to do that. I also can't make a bash script that pushes 'q' for me as far as I know.styfle– styfle2011年09月24日 04:30:22 +00:00Commented Sep 24, 2011 at 4:30 -
I noticed that when I login, it says 'You have mail' so that is already solved. But in case anyone is wondering, you can use a script like
echo "q" | mail
to see how many messages you have.styfle– styfle2011年09月24日 05:13:14 +00:00Commented Sep 24, 2011 at 5:13 -
Note that the mentioned notification is issued by the shell and can be turned off. Supposing you use Bash, see
MAIL
,MAILCHECK
andMAILPATH
in the man to know what you can expect.manatwork– manatwork2011年09月24日 11:08:22 +00:00Commented Sep 24, 2011 at 11:08 -
1You can also run biff to monitor the mailbox.casualunixer– casualunixer2011年09月25日 00:56:22 +00:00Commented Sep 25, 2011 at 0:56
-
this didn't work. I sent a mail to a local user and logged in to that user but didn't receive any mail.Necktwi– Necktwi2017年07月08日 07:33:33 +00:00Commented Jul 8, 2017 at 7:33
Try wall, http://linux.die.net/man/1/wall Maybe that will do the trick?
-
6This is pretty much the opposite of what he wants. He wants a command that leaves a message for a specific, logged out user; wall shows a message to all users currently logged inMichael Mrozek– Michael Mrozek2012年07月01日 01:44:23 +00:00Commented Jul 1, 2012 at 1:44