Bob Proulx wrote: > When I don't want to send mail I simply don't send mail. I guess it > is a little bit more work but I have done it so many times that I > don't even think about it anymore. I save the output to a temporary > file and then check to see if the file is empty before sending it off > in email.
Here is what I normally do. Here is a skeleton script that creates a temporary file, redirects all output there, then if there is output it emails it off. There are many ways to do this and I tinker it as needed. Bob #!/bin/sh unset tmpfile cleanup() { test -n "$tmpfile" && rm -f "$tmpfile" } trap "cleanup" EXIT # This next is special handling needed for dash only. trap "cleanup; trap - HUP; kill -HUP $$" HUP trap "cleanup; trap - INT; kill -INT $$" INT trap "cleanup; trap - QUIT; kill -QUIT $$" QUIT trap "cleanup; trap - TERM; kill -TERM $$" TERM # End dash special trap handling. tmpfile=$(mktemp) || exit 1 exec </dev/null >$tmpfile 2>&1 echo "...do stuff here that may make output..." echo "...do stuff here that may make output..." echo "...do stuff here that may make output..." exec >/dev/null 2>&1 # close previous output file if [ -s "$tmpfile" ]; then # There was output. Mail it. mailx -s "output from doing stuff" "$(whoami)" < "$tmpfile" fi exit 0
signature.asc
Description: Digital signature