#!/usr/bin/perl use strict; use warnings; use File::Spec; use Cache::FileCache (); unless ( @ARGV ) { my $script = (File::Spec->splitpath($0))[2]; die "$script another_program -and -its -args\n" . "caches the output from the command and only prints if it diff +ers fro" . "m the last time $script was run. This allows you to say `$scr +ipt who" . "is -i somedomain.org` and only have output show up when the w +hois ou" . "tput changes\n"; } my $pid; my $sleep_count = 0; do { $pid = open KID_TO_READ, "-|", @ARGV; unless (defined $pid) { warn "cannot fork: $!"; die "bailing out" if $sleep_count++ > 6; sleep 10; } } until defined $pid; my $self = File::Spec->rel2abs( $0 ); my $cache = Cache::FileCache->new( { namespace => $self } ); my $old = $cache->get( "@ARGV" ); my $new = do { local $/; <KID_TO_READ> }; if ($new ne $old) { print $new; $cache->set( "@ARGV", $new ); } close KID_TO_READ or warn "kid exited $?";
In reply to uniq_exec.pl - filters duplicate program output by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |