dirtdart has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl script on a Linux box that is used for sending alerts when certain conditions are met. One of the conditions is when it cannot ping an outside IP address. However, this doesn't do me any good when I'm offsite. Can anyone give me an idea how I would dial into an ISP and send an email through their service? I already have the dialup account and the email account, but I don't even know where to begin with this.

Replies are listed 'Best First'.
Re: Sending info through dialup
by roboticus (Chancellor) on Jan 05, 2011 at 13:20 UTC

    dirtdart:

    I'd suggest that you first find out how to start and stop the dialup connection, which will depend on which distribution of Linux you're using, and what type of dialup account you have. (I used to use a PPP connection back when I used dialup, it was pretty easy to configure and use. Some distros provide a ppp-on and ppp-off script to activate and terminate the link). Then you can write your script, and create a routine to send the EMail, such as:

    sub send_message { my ($to, $from, $msg) = @_; # Turn on PPP link, and give it time to connect `ppp-on`; sleep 5; # Create and send message $msg = MIME::Lite->new( From => $from, To => $to, Subject => 'ALERT', ); $msg->attach(Type=>'TEXT', Data=>$msg); $msg->send; # Wait long enough for delivery sleep 5; # Turn off the link `ppp-off`; }

    Error checking, correcting bugs and tuneup are your homework. ;^)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Although it doesn't look like OpenSuSE supports ppp-on directly, I was just able to find a page with the bash scripts on it, so that should be simple enough to implement and looks like it'll do exactly what I'm looking for. Thanks for the help!
        If ppp-on is not available, consider using wvdial which should be available on your distribution.
Re: Sending info through dialup
by chrestomanci (Priest) on Jan 05, 2011 at 13:11 UTC

    This is not really a perl question, it is a system configuration question. You need to:

    1. Dial your ISP and create an internet interface through that connection.
    2. Adjust the configuration of your email routing to use the new dialup interface.
    3. Send an email as normal.

    The first two steps can be solved by reading your system documentation. Once they are done, the last step will be easy.

    The problem with this approach, is that once your dial-up connection is created, the alert that tests if you can ping an external IP will not fail any more, so either your dial-up connection will hangup, and you will get a whole series of alert email as the alert fails and succeeds in a cycle with the dial-up connection, or the dial-up connection does not hang up, in which case the whole alert will become useless, as it will just end up testing the backup dial-up connection instead of your main one.

    Instead, can I suggest that you investigate sending some alerts via SMS text message as well as by email. Create a class of most serous problems that go via text as well, and include the 'no external connectivity' problem in that class. That way you are not confusing the alerting with your backup connection.

      The problem with this approach, is that once your dial-up connection is created, the alert that tests if you can ping an external IP will not fail any more, so either your dial-up connection will hangup, and you will get a whole series of alert email as the alert fails and succeeds in a cycle with the dial-up connection, or the dial-up connection does not hang up, in which case the whole alert will become useless, as it will just end up testing the backup dial-up connection instead of your main one.

      There are monitoring systems like nagios that can be configured to only send emails if the ping status changes.

      Now if the link goes down, it'll send an email, which the local mail server will hopefully keep in its spool until the second link is up again, and then send it. When the link goes up, the monitoring system will issue a second mail. If you're familiar with the setup, you know what that means (ie that the backup link works). So I don't really see a problem here, at least if the system is configured properly

      Thank you. I don't think that the loop is going to be a problem as my coding logic was more along the lines of:

      Test if good then sleep if not good then dial, send message, hangup loop

      However, the system configuration is where I'm having the trouble. I was hoping some adventurous monk had written a module that would do something similar to this, but alas it appears my hopes are in vain.

      As for SMS, my boss is too cheap and paranoid to pay for text messaging on our phones, so I'm stuck with Google Voice which does not have an email-to-text gateway.

Re: Sending info through dialup
by samarzone (Pilgrim) on Jan 05, 2011 at 13:03 UTC

    If you have access to an SMTP server you can take help of Net::SMTP

    --
    Regards
    - Samar
      Thank you. I actually do have that part, that's how I initially send my alerts. However, when the line goes down, I need to dial into an ISP, change my gateway and send through their system. That's the part that's stumping me.