I have a process that dumps millions of lines to the console while it runs. I'd like to run this in a cronjob but to avoid sending multi-MB mails, I'd like to restrict the output in the case of a success (exit == 0) to 0 lines and in case of an error (exit != 0) to the last 20 lines.
Any ideas to achieve this with little effort? Maybe a few lines of perl or a smart use of standard tools?