Created
September 16, 2012 19:17
htaccessdynamic.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I do not understand how to modify the code to accept multiple no-ip for example. Any ideas? Thank you!