--- sms.alert 2003/02/14 14:52:02 1.5 +++ sms.alert 2003/10/28 17:37:05 1.8 @@ -20,6 +20,7 @@ # -f send flash sms (directly to screen) # -x send extended message (all output, smstools with split it in # multiple smses if needed) +# -i hh:mm-hh:mm send sms only if it falls in this interval # # it users file /usr/local/etc/sms.addressbook as addressbook in format # @@ -28,7 +29,7 @@ # where 123456 is phone number (with country prefix, but without +) and # name is alias used like: # -# sms.alter -f dobrica +# sms.alert -f dobrica # # in mon.cf @@ -38,7 +39,7 @@ use strict; my %opt; use Getopt::Std; -getopts ("S:s:g:h:t:l:uf"); +getopts ("S:s:g:h:t:l:ufi:", \%opt); # read addressbook my %name2phone; @@ -63,6 +64,18 @@ my $summary = shift @MSG; chomp $summary; +if ($opt{i}) { + if ($opt{i} =~ /(\d+):(\d+)-(\d+):(\d+)/) { + my $from = $1 * 60 + $2; + my $to = $3 * 60 + $4; + my ($sec,$min,$hour) = localtime(time); + my $t = $hour * 60 + $min; + exit 0 if ($t < $from || $t > $to); + } else { + die "interval time format: hh:mm-hh:mm" + } +} + $summary = $opt{S} if $opt{S}; my ($wday,$mon,$day,$tm) = split (/\s+/, localtime); @@ -79,13 +92,16 @@ # add rest of text $sms .= join("\n",@MSG) if $opt{x}; +my $suffix = 0; + foreach my $to (@ARGV) { - if (open(SMS, "> $sms_outgoing/mon$$")) { + if (open(SMS, "> $sms_outgoing/mon-$$-$suffix")) { 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; + $suffix++; } else { die "could not open sms file in '$sms_outgoing': $!"; }