September 14, 2008
Ever had to run a program by cron which writes always stuff to stdout and you therefore get every time a mail from cron? You did an
> /dev/null to get rid of the messages but errors are not written to stderr by this program but also to stdout?
I have sometimes that problem and therefore I’ve written a small python script which is run by cron and launches itself the real program. It takes any output of that program and filters it by configured regular expression rules. Everything that matches a rules is not reported. As soon as one line does not match, this line is reported and followed by the full output of the program to make the error finding easier.
I often let programs run in verbose mode, as it is filtered anyway by the python script and if an error occurs it is nice to have more information at hand. The python script also forwards any provided parameter to the real program.
There is the python script filterOutput.py. Just download it, set the execute permissions and open it in an file editor. following 3 variables are interesting for you:
- programPath: the path to which the script should change before starting the program
- programCommand: the full path of the program to launch and filter
- regexList: the list of regular expressions rules which are used to filter the output of the called programm