Skip to content

Instantly share code, notes, and snippets.

@jasontucker
Created September 16, 2012 19:17
Show Gist options
  • Save jasontucker/3733952 to your computer and use it in GitHub Desktop.
Save jasontucker/3733952 to your computer and use it in GitHub Desktop.
htaccessdynamic.sh
#!/bin/bash
## Example:
## /bin/sh ~/htaccessdynamic.sh myhostname.dyndns-remote.com ~/infinatewp.mydomain.com/.htaccess
dynDomain="$1"
htaccessLoc="$2"
dynIP=$(/usr/bin/dig +short $dynDomain)
echo "dynip: $dynIP"
# verify dynIP resembles an IP
if ! echo -n $dynIP | grep -Eq "[0-9.]+"; then
exit 1
fi
# if dynIP has changed
if ! cat $htaccessLoc | /bin/grep -q "$dynIP"; then
# grab the old IP
oldIP=`cat ~/htold-ip.txt`
# output .htaccess file
echo "order deny,allow" > $htaccessLoc 2>&1
echo "allow from $dynIP" >> $htaccessLoc 2>&1
echo "allow from x.x.x.x" >> $htaccessLoc 2>&1
echo "deny from all" >> $htaccessLoc 2>&1
# save the new ip to remove next time it changes, overwriting previous old IP
echo $dynIP > ~/htold-ip.txt
fi
@PaulRayden
Copy link

I do not understand how to modify the code to accept multiple no-ip for example. Any ideas? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment