summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlocalmarkdown2sms31
1 files changed, 23 insertions, 8 deletions
diff --git a/localmarkdown2sms b/localmarkdown2sms
index 51d3bf9..163e732 100755
--- a/localmarkdown2sms
+++ b/localmarkdown2sms
@@ -126,10 +126,31 @@ foreach my $file (read_dir( $path )) {
}
}
+sub sendmsg {
+ my ($phone, $desc, $msg) = @_;
+
+ unless ($DUMMY) {
+ system {'/usr/share/kannel/contrib/sendsms' } $phone, $msg;
+ print STDERR "Done $desc\n" if ($DEBUG);
+ } else {
+ print STDERR "\n --> $desc\n";
+ print STDERR $msg . "\n";
+ }
+}
+
my ($phone) = shift @ARGV;
-my ($key) = shift @ARGV;
+my ($key) = lc (shift @ARGV);
my $num_children = $#{ $reply{$key} } + 1; # How many children we'll create
+
+if (0 == $num_children) {
+ &sendmsg($phone, "fallback message", "Hmmm, strange, the word \"$key\" is unknown. Perhaps you typed it wrong?\n\nPlease try again.");
+ exit;
+}
+
+if (0 == $num_children) {
+}
+
$SIG{CHLD} = 'IGNORE'; # Don't worry about reaping zombies
# Spawn off some children
@@ -145,13 +166,7 @@ for my $num ( 0 .. $num_children - 1 ) {
run_fork {
child {
sleep($delay{$key}[$num]) unless ($NOSLEEP);
- 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";
- }
+ &sendmsg($phone, "reply #$num [" . $delay{$key}[$num] . "s]", $reply{$key}[$num]);
exit;
}
parent {