5 chronic - runs a command quietly unless it fails
13 chronic runs a command, and arranges for its standard out and standard
14 error to only be displayed if the command fails (exits nonzero or crashes).
15 If the command succeeds, any extraneous output will be hidden.
17 A common use for chronic is for running a cron job. Rather than
18 trying to keep the command quiet, and having to deal with mails containing
19 accidental output when it succeeds, and not verbose enough output when it
20 fails, you can just run it verbosely always, and use chronic to hide
21 the successful output.
23 0 1 * * * chronic backup # instead of backup >/dev/null 2>&1
27 Copyright 2010 by Joey Hess <id@joeyh.name>
29 Original concept and "chronic" name by Chuck Houpt.
31 Licensed under the GNU GPL version 2 or higher.
37 use IPC
::Run
qw( start pump finish timeout );
40 die "usage: chronic COMMAND...\n";
44 my $h = IPC
::Run
::start \
@ARGV, \
*STDIN
, \
$out, \
$err;
46 my $ret=$h->full_result;
48 if ($ret >> 8) { # child failed
52 elsif ($ret != 0) { # child killed by signal