stop logging when executing a script

Hi guys if for every command you issued successfully where to be logged from a script and them sent an email to the admistrator how could i stop that so that i wouldnt have to delete admin mail all the time. I would only want to produce output if there was an error.

Are you talking about a shell script? If so, what shell?

just bash shell script

Bash scripts do not normally cause anything to be logged anywhere. Perhaps you can describe the scenario and environment where this is happening in a bit more detail.

On a hunch, I'm guessing you might be talking about a cron job or similar which generates output which then gets sent to the administrator. In general terms, you can suppress regular output by redirecting it to /dev/null, like so:

verbosecommand >/dev/null

If verbosecommand is correctly implemented, error messages will not be suppressed by this redirection (this is why we have separate "standard output" and "standard error"; the above discards only the "standard output").

yes i am talking about a cron job so if this script where to run as a cron job process and it would send mail to the administrator. I would only want it to send error messages to the log file. Would the above work ok?

That's the idea, yes. To be on the safe side, perhaps you can start by redirecting to a real file, instead of /dev/null, and check after the job completes that the file doesn't contain useful information. If the job is a shell script (or, for that matter, a binary that you have the source code for), it might be a useful exercise to change it so it doesn't emit spurious output, in keeping with a great Unix design principle. Maybe there could be a separate --quiet option for this.

In order to be able to test this without waiting for cron to kick in, and also to keep your crontab simple, you might want to create a wrapper script which sets up the redirections etc, and invoke that from your crontab instead of the real thing.