Use tee command to send output to a file and email

Problem

You would like to send the error output from a command or a script to both an error file and an email.

Solution

By using tee, you could do the following:

command_with_parameters 2>&1 | tee /log_file_name | mail -s 'Command error' me@mydomain.com