Subject: Re: bin/25553: ntptrace as an awk program can't accept options
To: NetBSD Bugs <netbsd-bugs@netbsd.org>
From: Geoff Wing <gcw@pobox.com>
List: netbsd-bugs
Date: 05/14/2004 12:21:12
"Greg A. Woods" <woods@weird.com> output:
:[ On , May 13, 2004 at 11:28:39 (+1000), gcw@primenet.com.au wrote: ]
:> Subject: bin/25553: ntptrace as an awk program can't accept options
:> >Fix:
:> 	Revert to C program?
:or maybe write a wrapper shell script to invoke the AWK program
:appropriately....

I did consider that very briefly but didn't really think it was the most
appropriate solution, however if we're stuck with the awk version . . .

BTW, the "-v" option isn't implemented in the awk version.

Regards,
Geoff


--- /usr/src/usr.sbin/ntp/ntptrace/ntptrace.awk	2003-12-30 15:10:13.000000000 +1100
+++ ntptrace	2004-05-14 12:14:49.000000000 +1000
@@ -1,4 +1,6 @@
-#!/usr/bin/awk -f
+#!/bin/sh
+
+/usr/bin/awk '
 #
 # Based on a perl script by
 # John Hay -- John.Hay@icomtek.csir.co.za / jhay@FreeBSD.org
@@ -83,7 +85,7 @@
 
     printf("%s: stratum %d, offset %f, synch distance %f",
 	dhost(host), stratum, offset, syncdistance)
-    if (stratum == 1) printf(", refid '%s'", refid)
+    if (stratum == 1) printf(", refid '\''%s'\''", refid)
     printf("\n")
 
     if (stratum == 0 || stratum == 1 || stratum == 16)
@@ -91,7 +93,7 @@
     if (refid ~ /127\.127\.[0-9]{1,3}\.[0-9]{1,3}/)
 	exit 0
 
-    command = "ntpq -n -c 'pstat " peer "' " host
+    command = "ntpq -n -c '\''pstat " peer "'\'' " host
     while (command | getline) {
 	gsub(/,/,"")
 	nvars = split($0, vars)
@@ -126,3 +128,4 @@
     getargs()
     do_one_server()
 }
+' $@