Skip to content

Instantly share code, notes, and snippets.

@itskenny0
Created July 8, 2024 08:27
Show Gist options
  • Save itskenny0/a45b264cbe94dfb7f00992b4ca67ee2e to your computer and use it in GitHub Desktop.
Save itskenny0/a45b264cbe94dfb7f00992b4ca67ee2e to your computer and use it in GitHub Desktop.
Copy dhcp.leases to /etc/hosts on OpenWrt for AdGuard Home
#!/bin/bash
# converts /tmp/dhcp.leases to /etc/hosts format for adguardhome to show hostnames
# Paths to the files
HOSTS_FILE="/etc/hosts"
DHCP_LEASES_FILE="/tmp/dhcp.leases"
TEMP_FILE="/tmp/dhcp_hosts.tmp"
sed '/### DHCP LEASES START ###/,/### DHCP LEASES END ###/d' $HOSTS_FILE > $TEMP_FILE
mv $TEMP_FILE $HOSTS_FILE
echo "### DHCP LEASES START ###" >> $HOSTS_FILE
awk '{print $3 " " $4}' $DHCP_LEASES_FILE >> $HOSTS_FILE
echo "### DHCP LEASES END ###" >> $HOSTS_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment