From owner-freebsd-questions Mon Jul 5 14:47:56 1999 Delivered-To: freebsd-questions@freebsd.org Received: from metis.host4u.net (metis.host4u.net [209.150.128.22]) by hub.freebsd.org (Postfix) with ESMTP id CB12214C94 for ; Mon, 5 Jul 1999 14:47:50 -0700 (PDT) (envelope-from dan.langille@dvl-software.com) Received: from wocker (210-55-152-24.ipnets.xtra.co.nz [210.55.152.24]) by metis.host4u.net (8.8.5/8.8.5) with SMTP id QAA01586; Mon, 5 Jul 1999 16:47:37 -0500 Message-Id: <199907052147.QAA01586@metis.host4u.net> From: "Dan Langille" Organization: DVL Software Limited To: Anton Berezin Date: Tue, 6 Jul 1999 09:47:38 +1200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: running frequent cron perl scripts Reply-To: dan.langille@dvl-software.com Cc: Burke Gallagher , freebsd-questions@FreeBSD.ORG 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 +1200 X-mailer: Pegasus Mail for Win32 (v3.01d) Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 = ; close FILE; } else { &write_OldIP; } } sub write_OldIP{ if (open(FILE,">$IPFilename")) { print FILE $ip; close FILE; } else { print "Error: 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