/[mon-modules]/sms.alert
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sms.alert

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by dpavlin, Fri Feb 14 14:54:45 2003 UTC revision 1.8 by dpavlin, Tue Oct 28 17:37:05 2003 UTC
# Line 20  Line 20 
20  #       -f      send flash sms (directly to screen)  #       -f      send flash sms (directly to screen)
21  #       -x      send extended 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    #       -i hh:mm-hh:mm  send sms only if it falls in this interval
24  #  #
25  # it users file /usr/local/etc/sms.addressbook as addressbook in format  # it users file /usr/local/etc/sms.addressbook as addressbook in format
26  #  #
# Line 28  Line 29 
29  # where 123456 is phone number (with country prefix, but without +) and  # where 123456 is phone number (with country prefix, but without +) and
30  # name is alias used like:  # name is alias used like:
31  #  #
32  # sms.alter -f dobrica  # sms.alert -f dobrica
33  #  #
34  # in mon.cf  # in mon.cf
35    
# Line 38  my $sms_addressbook = "/usr/local/etc/sm Line 39  my $sms_addressbook = "/usr/local/etc/sm
39  use strict;  use strict;
40  my %opt;  my %opt;
41  use Getopt::Std;  use Getopt::Std;
42  getopts ("S:s:g:h:t:l:uf", \%opt);  getopts ("S:s:g:h:t:l:ufi:", \%opt);
43    
44  # read addressbook  # read addressbook
45  my %name2phone;  my %name2phone;
# Line 63  my @MSG=<STDIN>; Line 64  my @MSG=<STDIN>;
64  my $summary = shift @MSG;  my $summary = shift @MSG;
65  chomp $summary;  chomp $summary;
66    
67    if ($opt{i}) {
68            if ($opt{i} =~ /(\d+):(\d+)-(\d+):(\d+)/) {
69                    my $from = $1 * 60 + $2;
70                    my $to = $3 * 60 + $4;
71                    my ($sec,$min,$hour) = localtime(time);
72                    my $t = $hour * 60 + $min;
73                    exit 0 if ($t < $from || $t > $to);
74            } else {
75                    die "interval time format: hh:mm-hh:mm"
76            }
77    }
78    
79  $summary = $opt{S} if $opt{S};  $summary = $opt{S} if $opt{S};
80    
81  my ($wday,$mon,$day,$tm) = split (/\s+/, localtime);  my ($wday,$mon,$day,$tm) = split (/\s+/, localtime);
# Line 79  $sms .= "Secs until next alert: $opt{l}\ Line 92  $sms .= "Secs until next alert: $opt{l}\
92  # add rest of text  # add rest of text
93  $sms .= join("\n",@MSG) if $opt{x};  $sms .= join("\n",@MSG) if $opt{x};
94    
95    my $suffix = 0;
96    
97  foreach my $to (@ARGV) {  foreach my $to (@ARGV) {
98          if (open(SMS, "> $sms_outgoing/mon$$")) {          if (open(SMS, "> $sms_outgoing/mon-$$-$suffix")) {
99                  my $phone = $to;                  my $phone = $to;
100                  $phone = $name2phone{lc($to)} if ($name2phone{lc($to)});                  $phone = $name2phone{lc($to)} if ($name2phone{lc($to)});
101                  die "$phone is not phone number! " if ($phone !~ m/^\d+$/);                  die "$phone is not phone number! " if ($phone !~ m/^\d+$/);
102                  print SMS "To: $phone\n$sms";                  print SMS "To: $phone\n$sms";
103                  close SMS;                  close SMS;
104                    $suffix++;
105          } else {          } else {
106                  die "could not open sms file in '$sms_outgoing': $!";                  die "could not open sms file in '$sms_outgoing': $!";
107          }          }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.26