From eb115f7cd8f64bb5bfe95c98e10bf8ab845f9e47 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 28 Jun 2010 13:45:34 +0100 Subject: [PATCH] Add innduct-forall --- Makefile.am | 2 +- Makefile.in | 2 +- innduct-forall | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 innduct-forall diff --git a/Makefile.am b/Makefile.am index 1e91bea..124e9c1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,7 +40,7 @@ WARNINGS= \ CFLAGS = @CFLAGS@ $(WARNINGS) $(WERROR) $(CMDLINE_CFLAGS) bin_PROGRAMS = innduct -bin_SCRIPTS = innduct-stats-report +bin_SCRIPTS = innduct-stats-report innduct-forall man_MANS = innduct.8 innduct-stats-report.8 innduct_SOURCES = duct.c conn.c filemon.c infile.c recv.c xmit.c \ cli.c defer.c help.c statemc.c __oop-read-copy.c diff --git a/Makefile.in b/Makefile.in index 6340dc6..f61647f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -104,7 +104,7 @@ WARNINGS = -Wall -Wformat=2 -Wno-format-zero-length -Wshadow -Wpointer-arith CFLAGS = @CFLAGS@ $(WARNINGS) $(WERROR) $(CMDLINE_CFLAGS) bin_PROGRAMS = innduct -bin_SCRIPTS = innduct-stats-report +bin_SCRIPTS = innduct-stats-report innduct-forall man_MANS = innduct.8 innduct-stats-report.8 innduct_SOURCES = duct.c conn.c filemon.c infile.c recv.c xmit.c cli.c defer.c help.c statemc.c __oop-read-copy.c diff --git a/innduct-forall b/innduct-forall new file mode 100755 index 0000000..e26aab5 --- /dev/null +++ b/innduct-forall @@ -0,0 +1,58 @@ +#!/usr/bin/perl -w +use strict qw(vars refs); +use IO::Handle; +our $self= 'innduct-forall'; +our $deftable= '/etc/news/ducts.table'; + +our $usage=<] +where is a sh command and may contain + !site site name + !fqdn fqdn or empty string + !opts innduct options + !duct shorthand for !opts !site !fqdn + !! single ! +default ducts-table is $deftable +END + + +die "$self: bad usage\n$usage" unless + @ARGV>=1 && @ARGV<=2 && $ARGV[0] !~ m/^\-/; + +our $table= (@ARGV>1 ? shift @ARGV : $deftable); +our $pattern= shift @ARGV; + +our $maxexit= 0; + +open T, '<', $table or die "$self: $table: $!\n"; +while () { + s/^\s*//; s/\s+$//; + next unless m/^[^\#]/; + my @v= split /\s+/, $_, 3; + my %c; + foreach my $f (qw(site fqdn opts)) { + my $v= shift @v; + $v='' unless defined $v; + $c{$f}= $v; + } + $c{'fqdn'}= $c{'site'} if $c{'fqdn'} eq '='; + $c{'duct'}= "$c{opts} $c{site} $c{fqdn}"; + $c{'!'}= '!'; + $_= $pattern; + s/\!(\w+|\!)/ + my $v= $c{$1}; + die "$self: unknown substitution $1\n" unless defined $v; + $v; + /ge; + my $r= system $_; + die "$self: run command: $!\n" if $r<0; + warn "$self: $c{site}: wait status $r: $_\n" if $r>0; + $r |= 128 if $r>0 && $r<128; + $r>>=8 if $r>=256; + $maxexit=$r if $r>$maxexit; +} +die "$self: $table: read: $!\n" if T->error; +close T or die "$self: table: close: $!\n"; + +exit $maxexit; -- 2.30.2