Re: Handwritten sms.alert doesn't get executed
Am Freitag 01 Dezember 2006 17:36 schrieb David Nolan: > Looking at your script it should be an issue, you're not checking for > errors from getopt (for extra unparsed args..) When using a full-fledged getopts(), the messages get sent. I was assuming it would not die quietly, but obviously it did. Thanks for your suggestions :-) Regards, Steven ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon
Re: Handwritten sms.alert doesn't get executed
Am Freitag 01 Dezember 2006 17:36 schrieb David Nolan: > Looking at your script it should be an issue, you're not checking for > errors from getopt (for extra unparsed args..) I'll add them; nonetheless, I checked for extra unparsed args and there were none. > Who owns the file on disk is not necessarily the same as the user the > process is running as. Run 'ps waux | grep mon' or similar... Since > you're trying to open /dev/ttyS1 you need to make sure that device is > writable by the user mon is executing as. root is the user who runs the process. > I don't see any issues with the script offhand... Did you try adding > debugging code near the 'no connection with serial port' case? Yes, unsuccessful. > If you're still having issues, post your mon.cf snippet next... How much of a snippet? > -David Regards, Steven ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon
Re: Handwritten sms.alert doesn't get executed
On 12/1/06, Steven Schubiger <[EMAIL PROTECTED]> wrote: > > When testing your alert are you also passing the other options that > > Mon sets when calling an alert? i.e. '-g group -s service -h "list of > > hosts here"', etc... (See the Mon man page for full documentation.) > > No, I haven't, assuming it wasn't necessary. I'll give it a try. > Looking at your script it should be an issue, you're not checking for errors from getopt (for extra unparsed args..) > > What user do you run mon as? Have you tested su'ing to that user and > > running the script? > > -rwxr-xr-x 1 root root 111458 2003-05-28 10:25 mon > Who owns the file on disk is not necessarily the same as the user the process is running as. Run 'ps waux | grep mon' or similar... Since you're trying to open /dev/ttyS1 you need to make sure that device is writable by the user mon is executing as. > > Can you post a copy of your script for us to look at? (without any > > SMS numbers, of course...) > > Sure, here you go: > I don't see any issues with the script offhand... Did you try adding debugging code near the 'no connection with serial port' case? If you're still having issues, post your mon.cf snippet next... -David ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon
Re: Handwritten sms.alert doesn't get executed
Am Freitag 01 Dezember 2006 16:29 schrieb David Nolan: > You said "no absolute path specified", did you mean no non-absolute > paths specified? i.e. if your script runs a program named foobar from > /usr/local/bin it should be calling it as /usr/local/bin/foobar, not > assuming /usr/local/bin is in $PATH. (Alternatively you can set $PATH > in your script...) I was referring to the inclusion of alert scripts within the mon config file; should have called it "relative" though. > Try adding some debugging code in your script. i.e. if its perl add > something like: > open(LOG, ">/tmp/alertlog"); > ... > print LOG "got to step XXX\n"; > ... > print LOG "got to step YYY\n"; Tried it and was unsuccessful. > When testing your alert are you also passing the other options that > Mon sets when calling an alert? i.e. '-g group -s service -h "list of > hosts here"', etc... (See the Mon man page for full documentation.) No, I haven't, assuming it wasn't necessary. I'll give it a try. > What user do you run mon as? Have you tested su'ing to that user and > running the script? -rwxr-xr-x 1 root root 111458 2003-05-28 10:25 mon > Can you post a copy of your script for us to look at? (without any > SMS numbers, of course...) Sure, here you go: #!/usr/bin/perl use strict; use warnings; use Device::Modem; use Getopt::Std; my ($anser, %opts, @recipients, $summary); my ($modem, $msg); my $device = '/dev/ttyS1'; my $pin= 2130; my $sleep = 5; parse_args(); #check_len_msg(); main(); sub main { foreach my $recipient (@recipients) { init(); set_opts(); send_cmds($recipient); disconnect(); } } sub parse_args { getopts('S:v', \%opts); @recipients = @ARGV; usage() unless defined $opts{S}; #$msg = $opts{S}; $summary=; chomp($summary); $msg = { local $/; }; } sub usage { print < 160; } sub init { $modem = Device::Modem->new(port => $device); if ($modem->connect(baudrate => 9600)) { print "Connecting...\n" if $opts{v}; } else { print "Sorry, no connection with serial port!\n"; } } sub set_opts { $modem->is_active(); $modem->verbose(1); } sub send_cmds { my $recipient = shift; $modem->atsend("AT\r"); print $modem->answer()."\n" if $opts{v}; $modem->atsend("AT+CSCS=GSM\r"); print $modem->answer()."\n" if $opts{v}; $modem->atsend("AT+CPIN=?\r"); print $modem->answer()."\n" if $opts{v}; $modem->atsend("AT+CPIN?\r"); my $answer = $modem->answer()."\n"; $answer =~ s/(?:\+CPIN:\s\w+)\s*(.*)/$1/; print $answer if $opts{v}; $modem->atsend("AT+CMGC=?\r"); print $modem->answer()."\n" if $opts{v}; $modem->atsend("AT+CMGF=1\r"); print $modem->answer()."\n" if $opts{v}; my @msgs; while (length($msg) > 160) { my $msg_chunk = substr($msg, 0, 160); push @msgs, $msg_chunk; $msg = substr($msg, 160, length($msg)); } push @msgs, $msg; foreach my $msg (@msgs) { sleep($sleep); $modem->atsend("AT+CMGS=$recipient\r"); sleep($sleep); $modem->atsend("$msg\cz"); } } sub disconnect { $modem->disconnect(); } > -David Regards, Steven ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon
Re: Handwritten sms.alert doesn't get executed
I sent this earlier, but I must have sent it from the wrong address and its sitting in a moderation queue... -David -- Forwarded message -- From: David Nolan <[EMAIL PROTECTED]> Date: Dec 1, 2006 8:27 AM Subject: Re: Handwritten sms.alert doesn't get executed To: mon@linux.kernel.org On 12/1/06, Steven Schubiger <[EMAIL PROTECTED]> wrote: > Hi! > > I've been quite trying for a while to get a handwritten SMS executed by mon. > Everything is fine if I open a terminal and run the script with same > parameters as defined in mon.cf -- the SMS gets send. When run > by mon, nothing happens. > > Looked through the mailing list archive and found some familiar threads > which had some interesting remarks: > > I checked if > * permissions are right (same as for all other alerts) > * the interpreter line was valid (same as for all other alerts) > * no absolute path specified (same as for most other alerts) > * perl -c emits no warnings (same as for all other alerts) > > Furthermore, I checked whether the script runs, but obviously it > doesn't. I've examined the syslog and the output generated > from mon when called with the debugging flag, but they leave > me in a rather clueless state. > > Thanks in advance, > Steven > > Steven, Some suggestions for you: You said "no absolute path specified", did you mean no non-absolute paths specified? i.e. if your script runs a program named foobar from /usr/local/bin it should be calling it as /usr/local/bin/foobar, not assuming /usr/local/bin is in $PATH. (Alternatively you can set $PATH in your script...) Try adding some debugging code in your script. i.e. if its perl add something like: open(LOG, ">/tmp/alertlog"); ... print LOG "got to step XXX\n"; ... print LOG "got to step YYY\n"; When testing your alert are you also passing the other options that Mon sets when calling an alert? i.e. '-g group -s service -h "list of hosts here"', etc... (See the Mon man page for full documentation.) What user do you run mon as? Have you tested su'ing to that user and running the script? Can you post a copy of your script for us to look at? (without any SMS numbers, of course...) -David ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon
Re: Handwritten sms.alert doesn't get executed
Am Freitag 01 Dezember 2006 15:09 schrieb Amias Channer: > I feel your pain , have you checked for empty lines near your > service definitions ? > > e.g. > > hostname foobar 10.0.0.2 > > watch foobar > service wibble_ok > service wibble_also_ok > > service wibble_will_be_ignored > > hostname foobaz 10.0.0.3 > > watch foobar > > service wibble_will_also be_ignored > service none_of_the_others_will_run_despite_being_ok Yes, I had a look; there were indeed such blank lines, but removing them didn't improve the matter in any way. > This one bites my ass regularly especially with m4 generated configs. > > I'm looking at solving this problem in general and i think it can be done > by piping the config file through sed which could run a regex to filter > newlines around services. That said i am wary of adding more > post-processing to my config files and would like to fix it in the mon > source . That sounds nice. > I'm happy to produce a patch to solve this if people feed me the necessary > tuits. > > Anyone else implemented this or similar ? > > Toodle-pip > Amias Regards, Steven ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon
Re: Handwritten sms.alert doesn't get executed
On Fri, 1 Dec 2006 14:12:55 +0100 Steven Schubiger <[EMAIL PROTECTED]> wrote: > Hi! > > I've been quite trying for a while to get a handwritten SMS executed by mon. > Everything is fine if I open a terminal and run the script with same > parameters as defined in mon.cf -- the SMS gets send. When run > by mon, nothing happens. > > Looked through the mailing list archive and found some familiar threads > which had some interesting remarks: > > I checked if > * permissions are right (same as for all other alerts) > * the interpreter line was valid (same as for all other alerts) > * no absolute path specified (same as for most other alerts) > * perl -c emits no warnings (same as for all other alerts) > > Furthermore, I checked whether the script runs, but obviously it > doesn't. I've examined the syslog and the output generated > from mon when called with the debugging flag, but they leave > me in a rather clueless state. I feel your pain , have you checked for empty lines near your service definitions ? e.g. hostname foobar 10.0.0.2 watch foobar service wibble_ok service wibble_also_ok service wibble_will_be_ignored hostname foobaz 10.0.0.3 watch foobar service wibble_will_also be_ignored service none_of_the_others_will_run_despite_being_ok This one bites my ass regularly especially with m4 generated configs. I'm looking at solving this problem in general and i think it can be done by piping the config file through sed which could run a regex to filter newlines around services. That said i am wary of adding more post-processing to my config files and would like to fix it in the mon source . I'm happy to produce a patch to solve this if people feed me the necessary tuits. Anyone else implemented this or similar ? Toodle-pip Amias ___ mon mailing list mon@linux.kernel.org http://linux.kernel.org/mailman/listinfo/mon