You can use the tty tool to check if a script is called from the standard output :
if ! tty -s
then
exec >/dev/null 2>&1
else
MAIL_DEST="email@server.ext"
fi
- The command tty returns :
User Commands tty(1)
NAME tty - return user's terminal name
SYNOPSIS tty [-l] [-s]
DESCRIPTION The tty utility writes to the standard output the name of
the terminal that is open as standard input. The name that
is used is equivalent to the string that would be returned
by the ttyname(3C) function.
OPTIONS The following options are supported:
-l Prints the synchronous line number to which the
user's terminal is connected, if it is on an active
synchronous line.
-s Inhibits printing of the terminal path name, allow-
ing one to test just the exit status.
EXIT STATUS
The following exit values are returned:
0 Standard input is a terminal.
1 Standard input is not a terminal.
>1 An error occurred.