Created
March 26, 2021 21:33
-
-
Save tasoseng/3f676b1eaea3bd4d251df0e9831e9adc to your computer and use it in GitHub Desktop.
generate aquila wake on lan xml file from dhcpd.conf 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
#!/bin/bash | |
set -eu | |
if [ $# -ne 1 ]; then | |
echo "usage: $0 dhcp.conf" | |
exit 1 | |
fi | |
[ -f $1 ] || { echo "$1 does not exist" ; exit 2; } | |
DOMAIN="my.domain.local" | |
echo '<?xml version="1.0" encoding="utf-8"?> | |
<ArrayOfMachine xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' | |
while read -r name mac ip; do | |
netbios=$name.$DOMAIN | |
group=_myGroup${name%-*} | |
broadcast=$(echo "$ip"|awk -F. '{OFS=FS}$4=255') | |
echo "<Machine> | |
<Name>$name</Name> | |
<MAC>$mac</MAC> | |
<IP>$ip</IP> | |
<Broadcast>$broadcast</Broadcast> | |
<Netbios>$netbios</Netbios> | |
<Method>0</Method> | |
<Emergency>true</Emergency> | |
<ShutdownCommand /> | |
<Group>$group</Group> | |
<UDPPort>9</UDPPort> | |
<TTL>128</TTL> | |
<RemoteCommand /> | |
<Note /> | |
<UserID /> | |
<Password /> | |
<Domain /> | |
<ShutdownMethod>Legacy</ShutdownMethod> | |
<KeepAlive>false</KeepAlive> | |
<RepeatCount>1</RepeatCount> | |
</Machine>" | |
done < <(grep -Eh "^\s*host\s+" "$1" | awk '{ print $2, $6, $8}' |tr -d ';') | |
echo '</ArrayOfMachine>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment