Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help required in modifying a CRON script 1

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

Have a cron script running every 15 minutes that updates the servers at with current public Dynamic IP address.

The CRONTAB command line is
Code:
*/15 * * * * /var/www/zoneedit.sh

The content of /var/ is typically
Code:
wget -O - --http-user=MyName --http-passwd=Password '[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=www.mysite.net'[/URL]
wget -O - --http-user=MyName --http-passwd=Password '[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=mysite.net'[/URL]
As can be seen, there is no checking of the public IP address to see if any changes have been made. So unless there has been a change, executing the code in /var/ is a waste of time and resources.

So in pseudo code, the script would resemble this:-

If file /var/ does not exist, get the public IP address, save it to /var/ and execute the two wgets. (This is for the first time the script runs only.)

If file /var/ does exist, get the public IP address and save it to a variable. Compare the the content of /var/ to the variable.

If the same, do nothing.

If not the same, save the variable to /var/ and execute the two wgets.

Using this script means the linux server could check the public IP address more frequently than every 15 minutes, and, in theory, would appear to be a more efficient way of updating the servers at
In thread54-1632489, Noway2 provided the necessary code to save the public IP address to both variable and file.

Would appreciate it if someone could fill in the gaps as outlned above.

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Hi

More exactly you want to write yet another dynamic DNS client, as described in zoneedit.com's FAQ at "What are the specs of the dynamic update request?" ?
Code:
[gray]#!/bin/bash[/gray]

[navy]ipfile[/navy][teal]=[/teal][green][i]'/var/www/ipaddress'[/i][/green]

[teal][[[/teal] -f [green][i]"$ipfile"[/i][/green] [teal]]][/teal] [teal]&&[/teal] [navy]ipold[/navy][teal]=[/teal][green][i]"$(< "[/i][/green][navy]$ipfile[/navy][green][i]" )"[/i][/green]
[navy]ipnew[/navy][teal]=[/teal][green][i]"$( wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //;s/<.*$//' )"[/i][/green]

[b]if[/b] [teal][[[/teal] [green][i]"$ipold"[/i][/green] [teal]!=[/teal] [green][i]"$ipnew"[/i][/green] [teal]]];[/teal] [b]then[/b]
  echo [green][i]"$ipnew"[/i][/green] [teal]>[/teal] [green][i]"$ipfile"[/i][/green]
  wget -O - --http-user[teal]=[/teal]MyName --http-passwd[teal]=[/teal]Password [green][i]'[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=www.mysite.net'[/URL][/i][/green]
  wget -O - --http-user[teal]=[/teal]MyName --http-passwd[teal]=[/teal]Password [green][i]'[URL unfurl="true"]http://dynamic.zoneedit.com/auth/dynamic.html?host=mysite.net'[/URL][/i][/green]
fi

Feherke.
 
Feherke

Many thanks for your post.

Yes, it is another dynamic DNS client, but one that would appear to use less resources than the script posted or ddclient, neither of which check for change in the public IP address.

The other advantage being the frequency of running the script. As I understand it, updating zoneedit too often would not be 'welcomed' by the zoneedit servers.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top