--- sms.alert 2003/02/04 15:39:44 1.3 +++ sms.alert 2003/02/06 12:12:36 1.4 @@ -3,17 +3,34 @@ # sms.alert - send an alert via smstools available at # http://www.isis.de/~s.frings/smstools/ # -# based on qpage.alert by Jim Trocki, trockij@transmeta.com +# based on qpage.alert and mail.alert by Jim Trocki, trockij@transmeta.com # # usage: -# sms.alter [-f][-l][-u] 385abxxxxxx|name[ 12345|name...] +# sms.alter [flags...] -g group -s system 385abxxxxxx|name[ 12345|name...] +# +# flags which are standard: # -# flags: # -u this is upalert +# -g grp group +# -s sys system +# -l time time to next alert +# +# flags specific to sms.alert: (all optional) +# # -f send flash sms (directly to screen) -# -l send long message (all output, smstools with split it in +# -x send extended message (all output, smstools with split it in # multiple smses if needed) # +# it users file /usr/local/etc/sms.addressbook as addressbook in format +# +# 123456 name +# +# where 123456 is phone number (with country prefix, but without +) and +# name is alias used like: +# +# sms.alter -f dobrica +# +# in mon.cf my $sms_outgoing = "/var/spool/sms/outgoing"; my $sms_addressbook = "/usr/local/etc/sms.addressbook"; @@ -21,7 +38,7 @@ use strict; my %opt; use Getopt::Std; -getopts ("s:g:fu", \%opt); +getopts ("S:s:g:h:t:l:uf"); # read addressbook my %name2phone; @@ -46,19 +63,25 @@ my $summary = shift @MSG; chomp $summary; +$summary = $opt{S} if $opt{S}; + my ($wday,$mon,$day,$tm) = split (/\s+/, localtime); my $ALERT = $opt{u} ? "UPALERT" : "ALERT"; my $sms = "From: mon\n"; -$sms .= "Flash: yes\n" if $opt{'f'}; +$sms .= "Flash: yes\n" if $opt{f}; $sms .= "\n$ALERT $opt{g}/$opt{s} $summary ($wday $mon $day $tm)\n"; -$sms .= join("\n",@MSG) if $opt{'l'}; +# add next alter time +$sms .= "Secs until next alert: $opt{l}\n" if $opt{l}; +# add rest of text +$sms .= join("\n",@MSG) if $opt{x}; -foreach my $to (shift @ARGV) { +foreach my $to (@ARGV) { if (open(SMS, "> $sms_outgoing/mon$$")) { my $phone = $to; $phone = $name2phone{lc($to)} if ($name2phone{lc($to)}); + die "$phone is not phone number! " if ($phone !~ m/^\d+$/); print SMS "To: $phone\n$sms"; close SMS; } else {