Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Jul 1999 09:47:38 +1200
From:      "Dan Langille" <dan.langille@dvl-software.com>
To:        Anton Berezin <tobez@plab.ku.dk>
Cc:        Burke Gallagher <burke@mcs.net>, freebsd-questions@FreeBSD.ORG
Subject:   Re: running frequent cron perl scripts
Message-ID:  <199907052147.QAA01586@metis.host4u.net>
In-Reply-To: <19990705232139.D8704@lion.plab.ku.dk>
References:  <19990705203750.BEYX282564.mta1-rme@wocker>; from Dan Langille on Tue, Jul 06, 1999 at 08:34:27AM %2B1200

next in thread | previous in thread | raw e-mail | index | archive | help
Anton, 

I've done some of the changes you suggested.  I don't have time to do 
them all right now.  I've also done some logging to demonstrate where 
the time is being taken:

Jul  6 09:42:44 ns DYNDNS[56310]: script stop
Jul  6 09:42:56 ns DYNDNS[56311]: script LWP
Jul  6 09:42:57 ns DYNDNS[56312]: script URL stuff
Jul  6 09:43:14 ns DYNDNS[56313]: script URL finish
Jul  6 09:43:14 ns DYNDNS[56314]: script stop

If the socket stuff is faster, I might try that.

The script now looks like this:

#!/usr/bin/perl
## Program Name: fetch2.cgi
##
## Nokia M10 address fetcher
##
##I hope that this program is useful to you. I make no claim as to this
##software's stability or value. It is offered as is. Use at your own risk.

system("logger -i -t DYNDNS script start");

$| = 1;
require LWP;

system("logger -i -t DYNDNS script LWP");

## Set the username and password for the M10
$user = "MadeHardBy";
$pass = "Telecom";

## Set the URL of the page containing the current IP for the M10
$URL = "http://192.168.1.254/shell/show+ip+interfaces";

## Set the left and right hand side of the Regular Expression that will find
## the IP within the page
$lhs = "inet ";
$rhs = " netmask 0 peer";

##  set the following to the name of a program you want run if its a new 
IP
$RunIfNew = "/home/dan/dns_update.sh";

$IPFilename = "myip.txt";

system("logger -i -t DYNDNS script URL stuff");

$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET,$URL,$h);
$req->authorization_basic($user,$pass);
$page = $ua->request($req);
$page->content() =~ /$lhs(\d*?\.\d*?\.\d*?\.\d*?)$rhs/;

system("logger -i -t DYNDNS script URL finish");

$ip=$1;
&get_OldIP;

if ($ip ne $OldIP) { 
    &write_OldIP;
   system( $RunIfNew);
   system("logger -i -t DYNDNS The IP Address has changed to $ip");
}

system("logger -i -t DYNDNS script stop");

## End of program.

sub get_OldIP{
    if (open(FILE,"<$IPFilename")) {
        $OldIP = <FILE>;
        close FILE;
    } else {
        &write_OldIP;
    }
}

sub write_OldIP{
    if (open(FILE,">$IPFilename")) {
        print FILE $ip;
        close FILE;
    } else {
        print "<STRONG>Error:</STRONG> couldn't write to file 
$IPFilename: $!\n";
    }
}
--
Dan Langille - DVL Software Limited
The FreeBSD Diary     - http://www.FreeBSDDiary.org/freebsd/
NZ FreeBSD User Group - http://www.nzfug.nz.freebsd.org/
The Racing System     - http://www.racingsystem.com/racingsystem.htm


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907052147.QAA01586>