28 |
# where 123456 is phone number (with country prefix, but without +) and |
# where 123456 is phone number (with country prefix, but without +) and |
29 |
# name is alias used like: |
# name is alias used like: |
30 |
# |
# |
31 |
# sms.alter -f dobrica |
# sms.alert -f dobrica |
32 |
# |
# |
33 |
# in mon.cf |
# in mon.cf |
34 |
|
|
38 |
use strict; |
use strict; |
39 |
my %opt; |
my %opt; |
40 |
use Getopt::Std; |
use Getopt::Std; |
41 |
getopts ("S:s:g:h:t:l:uf"); |
getopts ("S:s:g:h:t:l:uf", \%opt); |
42 |
|
|
43 |
# read addressbook |
# read addressbook |
44 |
my %name2phone; |
my %name2phone; |
71 |
|
|
72 |
my $sms = "From: mon\n"; |
my $sms = "From: mon\n"; |
73 |
$sms .= "Flash: yes\n" if $opt{f}; |
$sms .= "Flash: yes\n" if $opt{f}; |
74 |
$sms .= "\n$ALERT $opt{g}/$opt{s} $summary ($wday $mon $day $tm)\n"; |
$sms .= "\n$ALERT"; |
75 |
|
$sms .= " $opt{g}/$opt{s}" if ($opt{g} && $opt{s}); |
76 |
|
$sms .= " $summary ($wday $mon $day $tm)\n"; |
77 |
# add next alter time |
# add next alter time |
78 |
$sms .= "Secs until next alert: $opt{l}\n" if $opt{l}; |
$sms .= "Secs until next alert: $opt{l}\n" if $opt{l}; |
79 |
# add rest of text |
# add rest of text |
80 |
$sms .= join("\n",@MSG) if $opt{x}; |
$sms .= join("\n",@MSG) if $opt{x}; |
81 |
|
|
82 |
|
my $suffix = 0; |
83 |
|
|
84 |
foreach my $to (@ARGV) { |
foreach my $to (@ARGV) { |
85 |
if (open(SMS, "> $sms_outgoing/mon$$")) { |
if (open(SMS, "> $sms_outgoing/mon-$$-$suffix")) { |
86 |
my $phone = $to; |
my $phone = $to; |
87 |
$phone = $name2phone{lc($to)} if ($name2phone{lc($to)}); |
$phone = $name2phone{lc($to)} if ($name2phone{lc($to)}); |
88 |
die "$phone is not phone number! " if ($phone !~ m/^\d+$/); |
die "$phone is not phone number! " if ($phone !~ m/^\d+$/); |
89 |
print SMS "To: $phone\n$sms"; |
print SMS "To: $phone\n$sms"; |
90 |
close SMS; |
close SMS; |
91 |
|
$suffix++; |
92 |
} else { |
} else { |
93 |
die "could not open sms file in '$sms_outgoing': $!"; |
die "could not open sms file in '$sms_outgoing': $!"; |
94 |
} |
} |