Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’m trying to send user login logs to my email with the users name and location. After making the script I found that environment variables can’t run in this script, I’m hoping that someone out there can help me get this working even if it’s a security problem. Thanks for your time


ssmtp -oi << EOF
Subject: Login



email output is

Subject: Login  
share|improve this question
$SUDO_USER" from "$SSH_CLIENT is somewhat strange syntax. try to use "$SUDO_USER from $SSH_CLIENT" or even better ${SUDO_USER} etc. But this woh't help, I guess - where are the environment variables SUDO_USER and SSH_CLIENT defined? – ohno May 27 '12 at 18:25
idk where the environment variables are defined – Alexander May 27 '12 at 19:37
Type "set" and you will get a list of all the current variables. If you want something to persist put it in ~/.bashrc or ~/.bash_profile – virpara May 28 '12 at 5:37
i give it a try but no luck. thanks for trying virpara – Alexander May 29 '12 at 6:11

As an experiment, I added an env command (equivalent to printenv) to the end of /etc/update-motd.d/99-footer on my Ubuntu 12.04 system.

When I logged in again, the following lines were added to the end of my /etc/motd:


So $PATH and $PWD are the only environment variables that are set when 99-footer is running. That's why $SUDO_USER and $SSH_CLIENT aren't being expanded.

You need to send that e-mail from somewhere else, not from the process that updates /etc/motd.

share|improve this answer

If you change the script to:

echo "To:
Subject: Login


" | ssmtp -oi

Note use of double quotes. Variables should then be substituted.

share|improve this answer

Your Answer


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.