From: Joey Hess Date: Fri, 29 Oct 2010 19:49:33 +0000 (-0400) Subject: chronic: New command, runs a command quietly, unless it fails. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11eb9b1ae7b81f3bbf52047a7a8ec995b7808970;p=moreutils chronic: New command, runs a command quietly, unless it fails. --- diff --git a/Makefile b/Makefile index 377121d..3ffd562 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BINS=isutf8 ifdata ifne pee sponge mispipe lckdo parallel -PERLSCRIPTS=vidir vipe ts combine zrun -MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun.1 mispipe.1 lckdo.1 parallel.1 +PERLSCRIPTS=vidir vipe ts combine zrun chronic +MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun.1 chronic.1 mispipe.1 lckdo.1 parallel.1 CFLAGS=-O2 -g -Wall INSTALL_BIN?=install -s PREFIX=/usr diff --git a/README b/README index 548acf2..6a10099 100644 --- a/README +++ b/README @@ -1,32 +1,20 @@ This is a collection of the unix tools that nobody thought to write long ago, when unix was young. Currently it consists of these tools: -combine - combine the lines in two files using boolean operations -ifdata - get network interface info without parsing ifconfig output -isutf8 - check if a file or standard input is utf-8 -ifne - run a command if the standard input is not empty -lckdo - execute a program with a lock held (deprecated) -mispipe - pipe two commands, returning the exit status of the first -parallel - run multiple jobs at once -pee - tee standard input to pipes -sponge - soak up standard input and write to a file -ts - timestamp standard input -vidir - edit a directory in your text editor -vipe - insert a text editor into a pipe -zrun - automatically uncompress arguments to command +chronic: runs a command quietly unless it fails +combine: combine the lines in two files using boolean operations +ifdata: get network interface info without parsing ifconfig output +isutf8: check if a file or standard input is utf-8 +ifne: run a command if the standard input is not empty +lckdo: execute a program with a lock held (deprecated) +mispipe: pipe two commands, returning the exit status of the first +parallel: run multiple jobs at once +pee: tee standard input to pipes +sponge: soak up standard input and write to a file +ts: timestamp standard input +vidir: edit a directory in your text editor +vipe: insert a text editor into a pipe +zrun: automatically uncompress arguments to command Its web page is here: http://kitenet.net/~joey/code/moreutils/ diff --git a/chronic b/chronic new file mode 100755 index 0000000..783b5e0 --- /dev/null +++ b/chronic @@ -0,0 +1,63 @@ +#!/usr/bin/perl + +=head1 NAME + +chronic - runs a command quietly unless it fails + +=head1 SYNOPSIS + +chronic COMMAND... + +=head1 DESCRIPTION + +chronic runs a command, and agganges for its standard out and standard +error to only be displayed if the command fails (exits nonzero or crashes). +If the command succeeds, any extraneous output will be hidden. + +A common use for chronic is for running a cron job. Rather than +trying to keep the command quiet, and having to deal with mails containing +accidental output when it succeeds, and not verbose enough output when it +fails, you can just run it verbosely always, and use chronic to hide +the successful output. + + 5 0 * * * chronic rsync -v foo bar + +=head1 AUTHOR + +Copyright 2010 by Joey Hess + +Original concept and "chronic" name by Chuck Houpt. + +Licensed under the GNU GPL version 2 or higher. + +=cut + +use warnings; +use strict; +use IPC::Run qw( start pump finish timeout ); + +if (! @ARGV) { + die "usage: chronic COMMAND...\n"; +} + +my ($out, $err); +my $h = IPC::Run::start \@ARGV, \*STDIN, \$out, \$err; +$h->finish; +my $ret=$h->full_result; + +if ($ret >> 8) { # child failed + showout(); + exit ($ret >> 8); +} +elsif ($ret != 0) { # child killed by signal + showout(); + exit 1; +} +else { + exit 0; +} + +sub showout { + print STDOUT $out; + print STDERR $err; +} diff --git a/debian/changelog b/debian/changelog index 232f832..958e380 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +moreutils (0.43) UNRELEASED; urgency=low + + * chronic: New command, runs a command quietly, unless it fails. + * Now depends on IPC::Run, used by chronic. + + -- Joey Hess Fri, 29 Oct 2010 15:23:17 -0400 + moreutils (0.42) unstable; urgency=low * sponge: Guarantee that output file is always updated atomically, diff --git a/debian/control b/debian/control index 6af7d48..451240b 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Homepage: http://kitenet.net/~joey/code/moreutils/ Package: moreutils Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, libipc-run-perl Suggests: libtime-duration-perl, libtimedate-perl Conflicts: lckdo Replaces: lckdo @@ -18,6 +18,7 @@ Description: additional Unix utilities to write long ago, when Unix was young. . So far, it includes the following utilities: + - chronic: runs a command quietly unless it fails - combine: combine the lines in two files using boolean operations - ifdata: get network interface info without parsing ifconfig output - ifne: run a program if the standard input is not empty