Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Forked from lanefu/EdgeOSUpdateHostsBulk.sh
Last active January 17, 2020 03:44
Show Gist options
  • Save Zsoldier/e33c4827e173cfbc585471f4cc1941bc to your computer and use it in GitHub Desktop.
Save Zsoldier/e33c4827e173cfbc585471f4cc1941bc 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=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