#!/bin/bash
do_log "info" "false" "Live environment DHCP information collection: timeout='${network_timeout_dhcp}' seconds. Please wait."

dhclient -v -1 "${var_auto_nic}" 2>&1 | timeout "${network_timeout_dhcp}" dhcpdump -i "${var_auto_nic}" >> "${LOG_NIC}" || true
awk 'BEGIN {RS="---------------------------------------------------------------------------"; \
  ORS="---------------------------------------------------------------------------"} \
  NF {last=$0} END {print last}' "${LOG_NIC}" > "${LOG_NIC}".tmp && mv "${LOG_NIC}".tmp "${LOG_NIC}"

do_log "info" "false" "Live environment DHCP information collection: collection completed."

### Extract 'FQDN' from '${LOG_NIC}'
var_auto_fqdn=$(awk -F 'Host name' '/Host name/ {print $2}' "${LOG_NIC}" | xargs)

### Extract 'YIADDR' (Your IP Address) from '${LOG_NIC}'
var_dhcp_yiaddr=$(awk -F 'YIADDR:' '/YIADDR/ {print $2}' "${LOG_NIC}" | awk '{print $1}' | xargs)

### Extract 'SIADDR' (Server IP Address) from '${LOG_NIC}'
var_dhcp_siaddr=$(awk -F 'SIADDR:' '/SIADDR/ {print $2}' "${LOG_NIC}" | awk '{print $1}' | xargs)

### Extract 'Server Identifier' from '${LOG_NIC}'
var_dhcp_srv=$(awk -F 'Server identifier' '/Server identifier/ {print $2}' "${LOG_NIC}" | xargs)

### Extract 'GIADDR' (Gateway IP Address) from '${LOG_NIC}'
var_dhcp_giaddr=$(awk -F 'GIADDR:' '/GIADDR/ {print $2}' "${LOG_NIC}" | awk '{print $1}' | xargs)
