Skip to content

Instantly share code, notes, and snippets.

@alexalouit
Created March 29, 2020 13:07
Show Gist options
  • Save alexalouit/51962ff1a2901520074223c771dab6e6 to your computer and use it in GitHub Desktop.
Save alexalouit/51962ff1a2901520074223c771dab6e6 to your computer and use it in GitHub Desktop.
nfs export ip sync (use provider ptr)
/dir *(rw,no_root_squash,no_subtree_check)
#!/bin/bash
ip=`dig +short nslookup.domain.tld @ns.provider.com`
if /bin/ping -qc 3 $ip > /dev/null 2>&1; then
if [ ! -f /tmp/.ip-sync ]; then
logger "ip-sync: create ip rule to $ip"
sed -e "s/\*/$ip/" /etc/exports.default > /etc/exports
echo $ip > /tmp/.ip-sync
/usr/sbin/exportfs -r
else
if [ `cat /tmp/.ip-sync` != $ip ]; then
logger "ip-sync: update ip rule to $ip"
sed -e "s/\*/$ip/" /etc/exports.default > /etc/exports
echo $ip > /tmp/.ip-sync
/usr/sbin/exportfs -r
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment