Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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, 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).

share|improve this answer
    
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 Sep 24 '11 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 Sep 24 '11 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 and MAILPATH in the man to know what you can expect. –  manatwork Sep 24 '11 at 11:08
1  
You can also run biff to monitor the mailbox. –  casualunixer Sep 25 '11 at 0:56
add comment

Try wall, http://linux.die.net/man/1/wall Maybe that will do the trick?

share|improve this answer
1  
This 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 in –  Michael Mrozek Jul 1 '12 at 1:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.