Last active
January 17, 2020 03:44
-
-
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
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
## 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