Skip to content
Snippets Groups Projects
Verified Commit 2c773277 authored by David Beniamine's avatar David Beniamine
Browse files

Fix #22

parent 086d45be
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
if [ -z "$2" ] || [ "$1" != 'Name' ] && [ "$1" != 'MAC' ]
then
echo "Usage:"
echo "\t $0 MAC aa:bb:cc:dd:ee:ff"
echo "Or"
echo "\t $0 Name hostname"
exit 1
fi
lease_file="/var/lib/dhcp/dhcpd.leases"
cp $lease_file $lease_file.$(date "+%Y%m%d-%H%M%S")
if [ "$1" == 'MAC' ]
then
MAC=$2
awk -v MAC="$MAC" 'BEGIN{IN=0;ACCU=""} /^lease/{print ACCU;ACCU="";IN=1;do_print=1} /hardware ethernet/{if($3==MAC";"){do_print=0}} {ACCU=ACCU"\n"$0} /^}$/{if(do_print==1){print ACCU};IN=0;do_print=0;ACCU=""}' $lease_file > /tmp/$$
else
HOST="\"$2\""
awk -v HOST="$HOST" 'BEGIN{IN=0;ACCU=""} /^lease/{print ACCU;ACCU="";IN=1;do_print=1} /client-hostname/{if($2==HOST";"){do_print=0}} {ACCU=ACCU"\n"$0} /^}$/{if(do_print==1){print ACCU};IN=0;do_print=0;ACCU=""}' $lease_file > /tmp/$$
fi
sed '/^$/d' /tmp/$$ > $lease_file
systemctl restart isc-dhcp-server
......@@ -150,7 +150,7 @@ do
log "===== Begin host $name ($mac - $ip) ===="
cat $f >> $mainlog
log "===== End host $name ===="
if [ $(wc -l $f | awk '{print $1}') -gt 0 ]
if [ $(wc -l $f | awk '{print $1}') -lt 0 ]
then
DOWNS[$mac]=$name
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment