X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=notify;h=e13d97e6cb91a095842e59ed8c9295005bd2b2ed;hb=b33776ec58263cd3b1f6b844487f1aa7c7a99292;hp=597877e1d480e111e48dc4c2412b9d81db91e5ac;hpb=a19a1c335f9d1bbc72aa085f383406aa49e54e1b;p=post-pizza-notify.git diff --git a/notify b/notify old mode 100644 new mode 100755 index 597877e..e13d97e --- a/notify +++ b/notify @@ -1,33 +1,65 @@ #!/bin/bash set -e +usage () { cat <&2 "usage: ./notify recipientsfile 'message'"; exit 1;; +3.[^-]*) ;; +*) usage >&2; exit 1 ;; esac -rcpts="$1" -msg="$2" - -exec <"$rcpts" -line=0 -while read method data; do - line=$(( $line+1 )) - case "$method" in - #*|'') continue ;; - [^a-z]*) echo >&2 "huh ? $rcpts:$line: $method"; continue ;; - log=log-$method-$line.txt - exec >$log - set +e - printf >&2 "sms" - ./"via-$method" $data 2>&1 - rc=$? - set -e - if [ $rc != 0 ]; then - printf >&2 "-FAIL:%s\n" $log - else - printf >&2 " " - fi +senderinfo="$1" +rcpts="$2" +msg="$3" + +exec <"$senderinfo" +while read settingname value; do + case "$settingname" in + #*|'') continue;; + *) vn=PIZZANOTIFY_$settingname + eval "$vn=\"\$value\"" + export $vn + ;; + esac done -exec >&2 -echo >&2 + +perl <"$rcpts" -wne ' + use strict; + our @children; + our @passon; + BEGIN { @passon = @ARGV; @ARGV = (); } + s/^\s+//; + s/\s+$//; + next if m/^\#/; + next unless m/\S/; + die unless m/^([a-z]\w+)\s/; + my $method = $1; + my $child = fork; + defined $child or die $!; + if (!$child) { + exec "./onemethod", $method, @passon; + die $!; + } + push @children, $child; + END { + foreach my $child (@children) { + $!=$?=0; + my $got = waitpid $child, 0; + die $! unless $got==$child; + warn "$method [$child] $?" if $?; + } + } +' "$rcpts" "$msg" + +echo