Date: Tue, 6 Jul 1999 14:33:51 nzst From: "Dan Langille" <dan.langille@dvl-software.com> To: Burke Gallagher <burke@mcs.net> Cc: Anton Berezin <tobez@plab.ku.dk>, freebsd-questions@FreeBSD.org Subject: Re: running frequent cron perl scripts Message-ID: <37816b0f.6e09.0@actrix.gen.nz>
next in thread | raw e-mail | index | archive | help
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 (<SH>) { 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<FILE>; 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?37816b0f.6e09.0>