blob: 32621542eb6017e29723d62fbd4aa5861ea1102e [file] [log] [blame]
tiernof7aa8c42016-09-06 16:43:04 +02001#!/bin/bash
tierno9a61c6b2016-09-08 10:57:02 +02002##
3# Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.
4# This file is part of openvim
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18#
19# For those usages not covered by the Apache License, Version 2.0 please
20# contact with: nfvlabs@tid.es
21##
tiernof7aa8c42016-09-06 16:43:04 +020022
Jokin Garayefc2bfb2016-11-09 13:05:53 +010023if [ -e /var/lib/dhcp/dhcpd.leases ]
24then
25 awk '
26 ($1=="lease" && $3=="{"){ lease=$2; active="no"; found="no" }
27 ($1=="binding" && $2=="state" && $3=="active;"){ active="yes" }
28 ($1=="hardware" && $2=="ethernet" && $3==tolower("'$1';")){ found="yes" }
29 ($1=="client-hostname"){ name=$2 }
30 ($1=="}"){ if (active=="yes" && found=="yes"){ target_lease=lease; target_name=name}}
31 END{printf("%s", target_lease)} #print target_name
32 ' /var/lib/dhcp/dhcpd.leases
33elif [ -e /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases ]
34then
35 awk '
36 ($2=="'$1'"){ lease=$3; name=$4}
37 END{printf("%s", lease)}
38 ' /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases
39fi