summaryrefslogtreecommitdiff
path: root/localmarkdown2sms
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2009-08-08 14:26:15 +0200
committerJonas Smedegaard <dr@jones.dk>2009-08-08 14:26:15 +0200
commitf49212612fb15f8754c0c8630089fc4520465c8c (patch)
tree5dcd8e5f2a97667c9f5c3d75e36486997ec0a5c3 /localmarkdown2sms
parenta0a7dbf7d3baa296618d4913477f4dc8c73bd0a0 (diff)
Implement DEBUG and DUMMY modes.
Diffstat (limited to 'localmarkdown2sms')
-rwxr-xr-xlocalmarkdown2sms39
1 files changed, 30 insertions, 9 deletions
diff --git a/localmarkdown2sms b/localmarkdown2sms
index 380e1c5..08150c0 100755
--- a/localmarkdown2sms
+++ b/localmarkdown2sms
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
#
# /usr/local/sbin/localmarkdown2sms
# Copyright 2009 Jonas Smedegaard <dr@jones.dk>
@@ -21,6 +21,9 @@
use strict;
+use warnings;
+
+use Env qw[$DEBUG $DUMMY];
use File::Spec;
use File::Slurp;
use Time::Duration::Parse;
@@ -92,17 +95,35 @@ my $num_children = $#{ $reply{$key} }; # How many children we'll create
$SIG{CHLD} = 'IGNORE'; # Don't worry about reaping zombies
# Spawn off some children
+if ($DEBUG) {
+ print STDERR "queueing $num_children replies:";
+ for my $num ( 1 .. $num_children ) {
+ print STDERR " [" . $delay{$key}[$num] . "s]";
+ }
+ print STDERR "\n";
+}
for my $num ( 1 .. $num_children ) {
$reply{$key}[$num] =~ s/^\s*(.*?)\s*$/$1/s;
- run_fork { child {
- sleep($delay{$key}[$num]);
- system {'/usr/share/kannel/contrib/sendsms' } $phone, $reply{$key}[$num];
-# system "/bin/echo \"$phone: $reply{$key}[$num]\" >/tmp/sms_$num";
-# print STDERR $reply{$key}[$num];
- exit;
- } };
+ run_fork {
+ child {
+ sleep($delay{$key}[$num]);
+ unless ($DUMMY) {
+ system {'/usr/share/kannel/contrib/sendsms' } $phone, $reply{$key}[$num];
+ print STDERR "Done reply #$num [" . $delay{$key}[$num] . "s]\n" if ($DEBUG);
+ } else {
+ print STDERR "\n[" . $delay{$key}[$num] . "s]\n";
+ print STDERR $reply{$key}[$num] . "\n";
+ }
+ exit;
+ }
+ parent {
+ if ($DEBUG) {
+ my $child_pid = shift;
+ waitpid $child_pid, 0;
+ }
+ }
+ }
}
-warn ("spawned $num_children reply processes");
1;