I had a problem where my pppoe connection was lost two or three times a
day..

Since I use it to host works stuff. I needed it to be able to reconnect
itself..

so I wrote this script.. it needs a few perl modules installed.. but it
works great..

Its rough, but it works..

It goes and checks if it can access both google and yahoo and if it can't
get one.. (it doesn't need to be able to get both.)
it will restart the connection and email you to tell you it did..

copy everything from the start to the end lines.. and put it in a file.. put
it in /usr/bin or similiar.. and make it executable.. then put an entry in
contab like this:

-0,10,20,30,40,50 * * * *       /usr/sbin/monitor_connection >/dev/null


That will run the script every ten minutes., and fix the connection if it
goes down..
I have another version that monitors a dialup connection on another box..


###########  START OF SCRIPT   ################
#!/usr/bin/perl

use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use MIME::Lite;

my $url = 'http://www.yahoo.com';
my $url2 = 'http://www.google.com';

my @email_address = ('[EMAIL PROTECTED]');

my $SMTP_server = '127.0.0.1';
my $response = LWP::UserAgent->new(env_proxy => 1)->simple_request(GET
$url);

unless ($response->is_success)
   sleep 15;
   my $response2 = LWP::UserAgent->new(env_proxy => 1)->simple_request(GET
$url2);
      Bunless ($response2->is_success)
          {
       our $date = &get_date;
       my $message_txt = "ADSL connection was down and was restarted at
$date";

system('/usr/sbin/adsl-stop');
sleep 5;
system('/usr/bin/killall -9 adsl-connect');
system('/usr/bin/killall -9 pppd');
sleep 5;
system('/usr/sbin/adsl-start');
        foreach my $mailer (@email_address)
                    {
            &mail_data('[EMAIL PROTECTED]',"$mailer", "ADSL WARNING!
$date", "$message
                    }
          }# end of unless2
    } # end of unless1

#email and date subs follow.
sub mail_data
{
     #    usage: &mail_data("mail from address","Mail to address",
"subject", "message_txt");
    my $from_address = shift;
    my $to_address = shift;
    my $subject = shift;
    my $message_txt = shift;

     # Start the email body details.
     my $email_msg = MIME::Lite->new(
     From    => $from_address,
     To      => $to_address,
     #Cc     => '[EMAIL PROTECTED], [EMAIL PROTECTED]',
     Subject => $subject,
     Type    =>'TEXT',
     Data    => $message_txt
     );
  $email_msg->send('smtp', "$SMTP_server");
} # end of mail_data;
sub get_date
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date);
my @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
'Friday','Saturday');
my @months =
('January','February','March','April','May','June','July','August','Septembe
r','Oc
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour < 10)
{
$hour = "0$hour";
}
if ($min < 10)
{
$min = "0$min";
}
if ($sec < 10)
{
$sec = "0$sec";
}
$year += 1900;
$date = "$days[$wday], $months[$mon] $mday, $year at $hour\:$min\:$sec";
return $date;
}
exit(0);
#################### END OF SCRIPT ###################################


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Anne Wilson
Sent: Saturday, 14 December 2002 9:35 PM
To: [EMAIL PROTECTED]
Subject: Re: [newbie] Linux installation & Router Advice


On Friday 13 Dec 2002 10:18 pm, FemmeFatale wrote:
> All I'm asking is there any special things I need to know when installing
> linux behind a router?
>
> I bought one recently, works great with the windows installs... Took some
> fiddling but its all good now.
>
> So any special caveats, instructions, advice? warnings?
>
> Thx
> -------------
> FemmeFatale
>
> Good Decisions You boss Made:
> "We'll do as you suggest and go with Linux. I've always liked that
> character from Peanuts."
>
> - Source: Dilbert

FWIW, I had installed 8.2 when we put a router in for the adsl.  The
changeover from shared connection to PPPoE was painless, and I have seen no
problems that relate to the router issue.  When I upgraded to 9.0 no
problems
emerged either.

Maybe I'm missing something, but it seems on my experience to be a
non-issue.

HTH

Anne



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to