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.

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 am trying to run a script with the output to be emailed and watched(monitored), i try using this code:

    this are the output: >emailmessage
    echo "output here" >>emailmessage
    /bin/mail -s "$SUBJECT" "$EMAIL" < $emailmessage

and an email will be sent with the results but wont be displayed on my terminal, for now i use echo "email sent!" so i can be notified that the script was done running. How can i send it out and display it as well?

share|improve this question
Why don't you just put the echo "email sent" at the bottom of your script? If you need to make sure it ran OK, you can do if [ $? -eq 0 ]; then echo "email sent"; fi Or are you looking for something which will pop something up on your screen? – Mark Mann Jul 3 '11 at 11:43
Did you try tee[1] command? [1] unixhelp.ed.ac.uk/CGI/man-cgi?tee – alex Jul 3 '11 at 17:46
@mark, that's what i did earlier so i could be notified that the email was sent out,, @alex -- i need to learn the tee command very quick as well. thanks for all the help! – afbr1201 Jul 4 '11 at 9:18
up vote 4 down vote accepted

Assuming your script is running with a controlling terminal (so that the output has somewhere to go to be seen) you just need to add one line:

/bin/mail -s "$SUBJECT" "$EMAIL" < $emailmessage
cat $emailmessage
share|improve this answer
thanks, this is pretty simple and yet i aint aware i could do that.. Thanks! – afbr1201 Jul 4 '11 at 9:17
echo "To: $EMAIL"
echo "Subject: $SUBJECT"
echo ""
echo "$emailmessage" | tee >(/bin/mail -s "$SUBJECT" "$EMAIL")
echo "sent!"

This uses process substitution, so I've assumed you're using bash or ksh (or similar, check your shell's man page)

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.