Linux ntp file parsing?

I have been trying to build an analysis to collect the NTP server and peer systems for my Linux environment, both NTP and Chrony

I was able to hobble together a query from another post but would like some help to cleanup the output to just be the server name or ip, and not the entire line.

lines whose ((it as lowercase contains "server" or it as lowercase contains "peer") and it as string does not start with "#") of files ("/etc/inet/ntp.conf";"/etc/ntp.conf";"/etc/chrony.conf") whose (exists line whose ((it as lowercase contains "server" or it as lowercase contains "peer") and it as string does not start with "#") of it)

The output of this is:

server 10.10.10.66 minpoll 3 maxpoll 6 iburst
server 10.11.11.86 minpoll 3 maxpoll 6 iburst
server 10.12.12.166 minpoll 3 maxpoll 6 iburst prefer
peer 10.13.13.117 minpoll 6 maxpoll 8
peer 10.13.14.117 minpoll 6 maxpoll 8
peer 10.14.10.106 minpoll 4 maxpoll 6 iburst
peer 10.14.11.106 minpoll 4 maxpoll 6 iburst

I would really like to just have the IP addresses from the second field

Any help would be appreciated

Thank you

how about adding

preceding text of first " " of following text of first " " of lines whose ((it as lowercase contains "server" or it as lowercase contains "peer") and it as string does not start with "#") of files ("/etc/inet/ntp.conf";"/etc/ntp.conf";"/etc/chrony.conf") whose (exists line whose ((it as lowercase contains "server" or it as lowercase contains "peer") and it as string does not start with "#") of it)

Very close but get an error as there are multiple returns and after the first answer it gives an error and doesnt report the other server/peer entries for a given system:

ns3 10.12.23.191
ns3 Singular expression refers to non-unique object.

There should be about 4 other IPs for that server

sorry, it needed to be plural texts

preceding texts of first " " of following texts of first " " of lines whose ((it as lowercase contains "server" or it as lowercase contains "peer") and it as string does not start with "#") of files ("/etc/inet/ntp.conf";"/etc/ntp.conf";"/etc/chrony.conf") whose (exists line whose ((it as lowercase contains "server" or it as lowercase contains "peer") and it as string does not start with "#") of it)

2 Likes