From owner-freebsd-questions Sun Dec 9 8:58: 7 2001 Delivered-To: freebsd-questions@freebsd.org Received: from LKLDDC01.GARGANTUAN.COM (145bus8.tampabay.rr.com [24.94.145.8]) by hub.freebsd.org (Postfix) with ESMTP id 6E70437B416 for ; Sun, 9 Dec 2001 08:58:00 -0800 (PST) Received: by LKLDDC01.GARGANTUAN.COM with Internet Mail Service (5.5.2653.19) id ; Sun, 9 Dec 2001 11:57:59 -0500 Message-ID: <1DA741CA6767A144BAA4F10012536C27A923@LKLDDC01.GARGANTUAN.COM> From: "Oliver, Michael W." To: "'jacks@sage-american.com'" Cc: "'freebsd-questions@freebsd.org'" Subject: RE: Scripting help Date: Sun, 9 Dec 2001 11:57:59 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Jack, I just tried this on my server, and had to make a couple of tweaks.... This might be better.... #!/bin/sh while [ 1 ] do LAST_KNOWN_IP=`cat last_known_ip_file`; CURRENT_IP=`ifconfig sis0 | grep inet | grep -v inet6 | awk ' { print $2; } '`; if [ -z "$LAST_KNOWN_IP" ] then # run your dns ping program here using $CURRENT_IP echo $CURRENT_IP >last_known_ip_file; continue fi if [ "$LAST_KNOWN_IP" = "$CURRENT_IP" ] then sleep 30; continue else # run your dns ping program here using $CURRENT_IP echo $CURRENT_IP >last_known_ip_file; fi done EOF Of course, you would have to change the 'sis0' interface name to the one you are looking to monitor. HTH.... =========== Michael Oliver > -----Original Message----- > From: jacks@sage-american.com [mailto:jacks@sage-american.com] > Sent: Sunday, December 09, 2001 11:51 AM > To: Oliver, Michael W.; freebsd-questions@freebsd.org > Cc: Oliver, Michael W. > Subject: RE: Scripting help > > > Thanks Michael, will work on it.... > > At 11:32 AM 12.9.2001 -0500, Oliver, Michael W. wrote: > >Jack, > > > >Well, this will be my first script written from scratch, so > please be kind > >if I dork it up! Try this: > > > > > > > > > > > > > >#!/bin/sh > > > >while [ 1 ] > >do > > > > LAST_KNOWN_IP=`cat last_known_ip_file` > > CURRENT_IP=`ifconfig tun0 | grep inet | awk ' { print $2; } '` > > > > if [ -z "$LAST_KNOWN_IP"] > > then > > # run your dns ping program here using $CURRENT_IP > > echo $CURRENT_IP >last_known_ip_file > > continue > > fi > > > > if [ "$LAST_KNOWN_IP" = "$CURRENT_IP" ] > > then > > sleep 30 > > continue > > else > > # run your dns ping program here using $CURRENT_IP > > echo $CURRENT_IP >last_known_ip_file > > fi > > > >done > > > >EOF > > > > > > > > > > > > > > > > > >Please let me know how it turns out ;-) > > > >=========== > >Michael Oliver > > > > > > > > > > > > > > > > > > > > > > > >> -----Original Message----- > >> From: jacks@sage-american.com [mailto:jacks@sage-american.com] > >> Sent: Sunday, December 09, 2001 11:02 AM > >> To: freebsd-questions@freebsd.org > >> Subject: Scripting help > >> > >> > >> I have just set up an experimental FBSD 4.4-STABLE server > >> using DSL with > >> dynamic ip. Using ZoneEdit DNS services, the DNS can be > >> updated with a cron > >> script to still point to the proper name. I'm doing that now > >> using cron to > >> run the update script every 8 hours (the connection usually > >> runs for weeks > >> at a time without disconnect). > >> > >> However, I had rather have a script that runs every so often > >> (xminutes) and > >> doesn't bother the DNS server unless and ONLY if a changed in > >> the dynamic > >> IP has occured as a result of disconnect/reconnect. Here are > >> the functions > >> I see needed, but scripting language is not yet a decent > >> skill of mine. I > >> suspect others using dynamic IPs have this same need: Any guidence > >> appreciated once again. (I've looked at the ipcheck that uses > >> Python, but > >> rather not go that route if possible to do the simple > >> approach below). > >> > >> BEGIN (my crude) SCRIPT: > >> #!/bin/sh > >> PATH=/usr/local/bin:/usr/bin:/bin > >> ## This script would be run by cron every x_minutes > >> ## (files needed: "last_known_ip" and "my_current_ip") > >> ## Contents of last_known_ip (placed there manually at for > >> first output > >> ## by running ifconfig tun0 > last_known_ip > >> > >> tun0: flags=8051 mtu 1492 > >> inet 64.xxx.xx.20 --> 64.xxx.xx.254 netmask 0xffffffff > >> Opened by PID 149 > >> > >> ## Run update to my_current_ip file > >> # function: ifconfig tun0 > my_current_ip > >> > >> ##.... so the "my_current_ip" file would contain output of: > >> tun0: flags=8051 mtu 1492 > >> inet 64.xxx.xx.20 --> 64.xxx.xx.254 netmask 0xffffffff > >> Opened by PID 149 > >> > >> ## Now make comparison to see if dynamic ip has changed and > >> update DNS if > >> changed. > >> # function: look in my_current_ip and find the current ip > >> (64.xxx.xx.20) > >> # function: look in last_known_ip file and find ip (64.xxx.xx.66) > >> # function: if not same, then run DNS_ping_program to update > >> (ping command > >> here) > >> ## If change detected, update comparison file > >> # function: ifconfig tun0 > last_known_ip > >> # function: if same ip, then do nothing > >> END OF SCRIPT > >> > >> The above may be a crude approach, but best way I can define > >> the job for > >> now.... > >> > >> Best regards, > >> Jack L. Stone, > >> Server Admin > >> > >> Sage-American > >> http://www.sage-american.com > >> jacks@sage-american.com > >> > >> To Unsubscribe: send mail to majordomo@FreeBSD.org > >> with "unsubscribe freebsd-questions" in the body of the message > >> > > > > > > Best regards, > Jack L. Stone, > Server Admin > > Sage-American > http://www.sage-american.com > jacks@sage-american.com > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message