Skip to content

Instantly share code, notes, and snippets.

@tomgidden
Last active February 26, 2017 15:52
Show Gist options
  • Save tomgidden/0c8b5a21960a215b24657cc899dd165e to your computer and use it in GitHub Desktop.
Save tomgidden/0c8b5a21960a215b24657cc899dd165e to your computer and use it in GitHub Desktop.
Command line to partially cure get_iplayer's verbal diarrhoea. ie. don't show output unless/until ERROR or WARNING appears; then display it ALL.
get_iplayer --pvr 2>&1 | perl -ne 'if(/ERROR|WARNING/){$q=1;print $b;undef $b;}if($q){print $_;}else{$b.=$_;}'
@tomgidden
Copy link
Author

get_iplayer is excellent, but it does tend to be either too verbose, or absolutely silent, as the --verbose, --quiet and --silent options are a bit too hefty. Plus, if --pvr is specified, the behaviour changes again.

So, when run on a cron, you either get a massive email containing useless drivel, or nothing at all. Rather than just grep for errors (which would lose context), this perl one-liner will buffer all output. If no errors occur, then the script is silent, so cron won't send an email. If, however, it comes across ERROR or WARNING, it'll output everything up to the error, and continue outputting everything afterwards.

I really do wish someone would just improve the granularity of get_iplayer's logging instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment