Skip to content

Instantly share code, notes, and snippets.

@lanefu
Last active January 17, 2020 03:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lanefu/f4a8f23ea85d1811f05a95b9d9d34cbc to your computer and use it in GitHub Desktop.
Save lanefu/f4a8f23ea85d1811f05a95b9d9d34cbc to your computer and use it in GitHub Desktop.
Bulk Insert of active EdgeOS dhcp leases into /etc/hosts aka regenerate entries in /etc/hosts
## do this before hand
## vyatta will try to eval show under the wrong circumstances
show dhcp leases > /tmp/leases.txt
### dump below in a file, execute with bash
MY_INTERNAL_DOMAIN=your_internal_domain.local
IFS=$'\n'
for line in $(printf "$(cat /tmp/leases.txt|tail -n +3|awk '{print $6, $1, $2}')")
do
client_name=$(echo $line|awk '{print $1}')
client_ip=$(echo $line|awk '{print $2}')
client_mac=$(echo $line|awk '{print $3}')
dumb_command="/opt/vyatta/sbin/on-dhcp-event.sh commit $client_name $client_ip $client_mac $MY_INTERNAL_DOMAIN enable no"
eval "$dumb_command"
done 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment