Fixed some typos
[osm/openvim.git] / scripts / get_dhcp_lease.sh
1 #!/bin/bash
2 ##
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 ##
22
23 if [ -e /var/lib/dhcp/dhcpd.leases ]
24 then
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
33 elif [ -e /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases ]
34 then
35 awk '
36 ($2=="'$1'"){ lease=$3; name=$4}
37 END{printf("%s", lease)}
38 ' /var/lib/lxd-bridge/dnsmasq.lxdbr0.leases
39 fi