3 |
# sms.alert - send an alert via smstools available at |
# sms.alert - send an alert via smstools available at |
4 |
# http://www.isis.de/~s.frings/smstools/ |
# http://www.isis.de/~s.frings/smstools/ |
5 |
# |
# |
6 |
# based on qpage.alert by Jim Trocki, trockij@transmeta.com |
# based on qpage.alert and mail.alert by Jim Trocki, trockij@transmeta.com |
7 |
# |
# |
8 |
# usage: |
# usage: |
9 |
# sms.alter [-f][-l][-u] 385abxxxxxx|name |
# sms.alter [flags...] -g group -s system 385abxxxxxx|name[ 12345|name...] |
10 |
|
# |
11 |
|
# flags which are standard: |
12 |
# |
# |
|
# flags: |
|
13 |
# -u this is upalert |
# -u this is upalert |
14 |
|
# -g grp group |
15 |
|
# -s sys system |
16 |
|
# -l time time to next alert |
17 |
|
# |
18 |
|
# flags specific to sms.alert: (all optional) |
19 |
|
# |
20 |
# -f send flash sms (directly to screen) |
# -f send flash sms (directly to screen) |
21 |
# -l send long message (all output, smstools with split it in |
# -x send extended message (all output, smstools with split it in |
22 |
# multiple smses if needed) |
# multiple smses if needed) |
23 |
# |
# |
24 |
|
# it users file /usr/local/etc/sms.addressbook as addressbook in format |
25 |
|
# |
26 |
|
# 123456 name |
27 |
|
# |
28 |
|
# where 123456 is phone number (with country prefix, but without +) and |
29 |
|
# name is alias used like: |
30 |
|
# |
31 |
|
# sms.alter -f dobrica |
32 |
|
# |
33 |
|
# in mon.cf |
34 |
|
|
35 |
my $sms_outgoing = "/var/spool/sms/outgoing"; |
my $sms_outgoing = "/var/spool/sms/outgoing"; |
36 |
my $sms_addressbook = "/usr/local/etc/sms.addressbook"; |
my $sms_addressbook = "/usr/local/etc/sms.addressbook"; |
38 |
use strict; |
use strict; |
39 |
my %opt; |
my %opt; |
40 |
use Getopt::Std; |
use Getopt::Std; |
41 |
getopts ("s:g:fu", \%opt); |
getopts ("S:s:g:h:t:l:uf", \%opt); |
42 |
|
|
43 |
# read addressbook |
# read addressbook |
44 |
my %name2phone; |
my %name2phone; |
63 |
my $summary = shift @MSG; |
my $summary = shift @MSG; |
64 |
chomp $summary; |
chomp $summary; |
65 |
|
|
66 |
|
$summary = $opt{S} if $opt{S}; |
67 |
|
|
68 |
my ($wday,$mon,$day,$tm) = split (/\s+/, localtime); |
my ($wday,$mon,$day,$tm) = split (/\s+/, localtime); |
69 |
|
|
70 |
my $ALERT = $opt{u} ? "UPALERT" : "ALERT"; |
my $ALERT = $opt{u} ? "UPALERT" : "ALERT"; |
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 .= join("\n",@MSG) if $opt{'l'}; |
$sms .= " $opt{g}/$opt{s}" if ($opt{g} && $opt{s}); |
76 |
|
$sms .= " $summary ($wday $mon $day $tm)\n"; |
77 |
|
# add next alter time |
78 |
|
$sms .= "Secs until next alert: $opt{l}\n" if $opt{l}; |
79 |
|
# add rest of text |
80 |
|
$sms .= join("\n",@MSG) if $opt{x}; |
81 |
|
|
82 |
foreach my $to (@ARGV) { |
foreach my $to (@ARGV) { |
83 |
if (open(SMS, "> $sms_outgoing/mon$$")) { |
if (open(SMS, "> $sms_outgoing/mon$$")) { |
84 |
my $phone = $to; |
my $phone = $to; |
85 |
$phone = $name2phone{lc($to)} if ($name2phone{lc($to)}); |
$phone = $name2phone{lc($to)} if ($name2phone{lc($to)}); |
86 |
|
die "$phone is not phone number! " if ($phone !~ m/^\d+$/); |
87 |
print SMS "To: $phone\n$sms"; |
print SMS "To: $phone\n$sms"; |
88 |
close SMS; |
close SMS; |
89 |
} else { |
} else { |