in CentOS 6.3, I have “/sbin/service iptables save” in cron. How do I set cron to only email when there is an error or, if possible, run “service” silently (unless there is an error)? If none of these options are possible, is running “iptables-save > /etc/sysconfig/iptables” instead the only remaining choice?
Well, the forum mangled what I typed, but I meant just:
/dev/null
What you mentioned there, " >/dev/null 2>&1", will cause all output, both regular and errors, to go to /dev/null… and it didn’t sound like that’s what you wanted.
By using just “>/dev/null”, only standard output is redirected to /dev/null, and errors will still be output, which will cause them to be emailed to you.
Please note though that this method of course only works if the script/application actually does send regular output to stdout and warnings/errors to stderr. Of course, a sane script should do that.