From owner-freebsd-questions Mon Jul 5 19:34: 9 1999 Delivered-To: freebsd-questions@freebsd.org Received: from mail.actrix.gen.nz (mail2.actrix.gen.nz [203.96.16.37]) by hub.freebsd.org (Postfix) with ESMTP id 38D0515281 for ; Mon, 5 Jul 1999 19:34:04 -0700 (PDT) (envelope-from dan.langille@dvl-software.com) Received: from actrix.gen.nz (www@lemuria.actrix.gen.nz [203.96.16.20]) by mail.actrix.gen.nz (8.9.1/8.9.1) with SMTP id OAA10941; Tue, 6 Jul 1999 14:33:41 +1200 (NZST) From: "Dan Langille" Reply-To: dan.langille@dvl-software.com To: Burke Gallagher Cc: Anton Berezin , freebsd-questions@FreeBSD.org Date: Tue, 6 Jul 1999 14:33:51 nzst Subject: Re: running frequent cron perl scripts X-Mailer: DMailWeb Web to Mail Gateway 2.1t, http://netwinsite.com/top_mail.htm Message-id: <37816b0f.6e09.0@actrix.gen.nz> X-User-Info: 202.37.52.5 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Burke, I've modified the script and added some debugging. Mostly because I don't know what I'm doing. Here's the current script and the output. I have no idea why it hangs. I managed to borrow a perl manual at work and found more about the parameters to send. I added a zero after looking at man 2 send. I don't know if that was correct or not. cheers. #!/usr/bin/perl # use Socket; use MIME::Base64; # ------------------------------------------------------------------------ # globals # ------------------------------------------------------------------------ $routerAddress =3D "192.168.1.254"; $username =3D "MadeHardBy"; $password =3D "Telecom"; $IPFilename =3D "myip.txt"; # ------------------------------------------------------------------------ # syslog # ------------------------------------------------------------------------ sub syslog( $ ) { my $msg =3D shift( @_ ); system("logger -i -t $msg"); } # ------------------------------------------------------------------------ # FetchM10Address # ------------------------------------------------------------------------ sub FetchM10Address() { my $encoded; my $httpRequest; my $httpResponse; my $sin; print "DYNDNS start\n"; $encoded =3D encode_base64( "$username:$password" ); $encoded =3D "$username:$password"; print "DYNDNS 2nd\n"; $httpRequest =3D "GET /shell/show+ip+interfaces 1.1\r\n" . "Accept: text/*, text/html\r\n" . "Authorization: Basic $encoded\r\n"; print "DYNDNS 3rd $httpRequest\n"; $httpResponse =3D ""; print "DYNDNS 4th\n"; socket( SH, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) || die "can not create socket, $!\n"; print "DYNDNS 5th\n"; $sin =3D sockaddr_in( 80, inet_aton($routerAddress) ); print "DYNDNS 6th\n"; connect( SH, $sin ) || die "can not connect to router, $!\n"; print "DYNDNS 7th\n"; send( SH, $httpRequest, 0 ); print "DYNDNS 8th\n"; while () { print "DYNDNS loop\n"; $httpResponse =3D $httpResponse . $_; } print "DYNDNS 9th\n"; close( SH ); $httpResponse =3D~ m/inet ([\d.]+) netmask 0 peer/; print "DYNDNS 10th\n"; return $1; } # ------------------------------------------------------------------------ # getLastIP # ------------------------------------------------------------------------ sub getLastIP() { my $OldIP =3D ""; if (open( FILE,"<$IPFilename" )) { $OldIP =3D; chomp( $OldIP ); close FILE; } return $OldIP; } # ------------------------------------------------------------------------ # writeIP # ------------------------------------------------------------------------ sub writeIP( $ ) { $ip =3D shift( @_ ); if (open( FILE, ">$IPFilename" )) { print FILE $ip; close FILE; } else { print "Error: couldn't write to file $IPFilename: $!\n"; } } # ------------------------------------------------------------------------ # main # ------------------------------------------------------------------------ print "DYNDNS\n"; syslog( "DYNDNS start" ); $currentIP =3D FetchM10Address(); $lastIP =3D getLastIP(); print "currentIP =3D $currentIP, lastIP =3D $lastIP\n"; if ($currentIP !=3D $lastIP) { print "change detected\n"; writeIP( $currentIP ); system "/home/dan/dns_update.sh"; syslog( "The IP Address has changed to $currentIP" ); } syslog( "DYNDNS stoped" ); $ perl get_ip.sh DYNDNS DYNDNS start DYNDNS 2nd DYNDNS 3rd GET /shell/show+ip+interfaces 1.1 Accept: text/*, text/html Authorization: Basic MadeHardBy:Telecom DYNDNS 4th DYNDNS 5th DYNDNS 6th DYNDNS 7th DYNDNS 8th =F2^C - Dan Langille To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message