skip to Main Content

Would like to return just "123.235.44.1" value from below. how do i do this?

# dhclient -v 
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/ens3/fa:16:3e:9e:33:25
Sending on   LPF/ens3/fa:16:3e:9e:33:25
Sending on   Socket/fallback
DHCPREQUEST for 123.123.123.123 on ens3 to 255.255.255.255 port 67 (xid=0x77420868)
DHCPACK of 123.123.123.123 from **123.235.44.1** (xid=0x68084277)
RTNETLINK answers: File exists
bound to 123.123.123.123 -- renewal in 33881 seconds.

a bash program that returns the dhcp server ip 123.235.44.1

2

Answers


  1. You need to redirect stderr to stdout in order to capture and filter to obtain the required value.

    dhclient -v 2>&1 | grep '^DHCPACK' | awk '{ print $5 }'
    
    Login or Signup to reply.
  2. You don’t need grep if you use awk

    dhclient -v 2>&1 | awk '/^DHCPACK/ { print $5 }'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search