LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bizarre dial out issue - cant just dial a number then quit (https://www.linuxquestions.org/questions/linux-newbie-8/bizarre-dial-out-issue-cant-just-dial-a-number-then-quit-642465/)

noob_d 05-15-2008 03:50 PM

bizarre dial out issue - cant just dial a number then quit
 
First, yes, I am a noob. I touched on Linux a little over the years.I rencently got LFS 6.3 to fully go on a laptop (I even wrote scripts for the process), and I know some of the basic commands. For a new project, I used net-install Debian and got Nagios up and running.
What I am trying to accomplish as part of Nagios' notification process is to have the server simply dial a phone number, wait 30 seconds, then hang up (and exit the command invoking that process). The reason for this is so my boss and I wake up during the night to a ringing phone.
It seems as though every program I have got to successfully call out (wvdial, cu, pon) takes far too long to timeout and exit. I do not want any extra waiting or attempting ppp connections, so that Nagios can move on to the next notification command.
From what I can figure, those programs I mentioned previously all call to CHAT to actually dial. For the life of me, I cannot make CHAT dial the modem from the command line. I cannot figure out where to put ttyS0 in the command, or if it even uses it. Also, I attempted to use a chatscript and reference chat to it, but there is no details on where/how/if you add the port.
Does anyone have any ideas, or know how to make CHAT work from the command line? Any help is appreciated. If you need any more details, I will gladly provide them as best I can.
Thank you,
Darrell

unSpawn 05-15-2008 04:48 PM

Quote:

Originally Posted by noob_d (Post 3154488)
It seems as though every program I have got to successfully call out (wvdial, cu, pon) takes far too long to timeout and exit. I do not want any extra waiting or attempting ppp connections, so that Nagios can move on to the next notification command.

What you want is an asynchronous, external handler. Something like the handler below should work (I mean, it can't be simpler than that). What it does is tell 'at' to queue the command 'wvdialconf /etc/nagios/wvdial_mgr.conf' for immediate execution. The only thing *you* have to do is prep your wvdial or ppp or whatever else you use to dial out.

Code:

# "wvdial-a-manager" command definition
define command{
command_name wvdial-a-manager
command_line echo 'wvdialconf /etc/nagios/wvdial_mgr.conf'|at now
}


chrism01 05-15-2008 06:45 PM

As this seems to be the problem:
"takes far too long to timeout and exit" I can think of a couple of solutions.
In bash, you put the phone cmd into the background

# Phone_and_terminate script
#!/bin/bash
phone_script &
#$! is last background cmd pid
sleep 30
kill -9 $!

In Perl, you'd use wrap a SIGALRM around it
To interrupt a long-running operation, set a SIGALRM handler to call die. Set an alarm with alarm, then eval your code:
Code:

$SIG{ALRM} = sub { die "timeout" };

eval {
    alarm(3600);
    # long-time operations here
    alarm(0);
};

if ($@) {
    if ($@ =~ /timeout/) {
                            # timed out; do what you will here
    } else {
        alarm(0);          # clear the still-pending alarm
        die;                # propagate unexpected exception
    }
}


noob_d 05-23-2008 08:16 AM

Well, I have found that I can set the S7 register to a lower time in wvdial.conf and the modem will just give up and exit the program. I appreciate the help.


All times are GMT -5. The time now is 10:45 PM.