I recently started using output from sysctl(8) to get information from
some FreeBSD systems in what I hope is a low-impact way.

I wanted to avoid installing or configuring any additional software on
the machines; as they didn't have an SNMP daemon running (and I'm not
the one who actually controls or runs them anyway), I was reluctant to
recommend making such changes to production systems.

But I did have a requirement to gather information as to resource
consumption on the production machines, so I thought that sysctl(8)
output might be of some use -- and it has (or so I believe).

But I ran into one mild annoyance:  Once I got a script working to
collect data from one machine, and I then tried running the script
(configured to collect information on the same OIDs), things were OK ...
as long as the new system was running the same revision of FreeBSD.

I realize that there will be changes in supported OIDs over time.  But
the current behavior of sysctl(8) is to (squawk unless -q is specified)
and bail as soon as it sees a request to report on the value of an OID
it doesn't know.

In my case, I believe it would be useful to provide an ability to tell
sysctl(8) to report on everything asked for that it does know, and
ignore the OIDs it doesn't know.

Is this percpetion so radical that I'm way off base?  If so, please
educate me as to why.

Otherwise, I'll plan on filing a PR with the attached patch, which adds
"-i" to sysctl(8)'s flags -- and which appears to work as described above:

localhost(8.0-C)[1] uname -a
FreeBSD localhost 8.0-CURRENT FreeBSD 8.0-CURRENT #769: Mon May 12 07:17:44 PDT 
2008     [EMAIL PROTECTED]:/common/S4/obj/usr/src/sys/CANARY  i386
localhost(8.0-C)[2] sysctl hw.ncpu kern.sched.quantum net.inet.ip.fw.enable
hw.ncpu: 1
sysctl: unknown oid 'kern.sched.quantum'
localhost(8.0-C)[3] sysctl -i hw.ncpu kern.sched.quantum net.inet.ip.fw.enable
hw.ncpu: 1
net.inet.ip.fw.enable: 1
localhost(8.0-C)[4] ^-i^-q
sysctl -q hw.ncpu kern.sched.quantum net.inet.ip.fw.enable
hw.ncpu: 1
localhost(8.0-C)[5] 

Peace,
david
-- 
David H. Wolfskill                              [EMAIL PROTECTED]
I submit that "conspiracy" would be an appropriate collective noun for cats.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.
Index: sysctl.8
===================================================================
RCS file: /cvs/freebsd/src/sbin/sysctl/sysctl.8,v
retrieving revision 1.64
diff -u -r1.64 sysctl.8
--- sysctl.8    28 Nov 2007 14:48:30 -0000      1.64
+++ sysctl.8    12 May 2008 19:14:08 -0000
@@ -82,6 +82,12 @@
 is specified, or a variable is being set.
 .It Fl h
 Format output for human, rather than machine, readability.
+.It Fl i
+Ignore unknown OIDs.
+The purpose is to make use of
+.Nm
+for collecting data from a variety of machines (not all of which
+are necessarily running exactly the same software) easier.
 .It Fl N
 Show only variable names, not their values.
 This is particularly useful with shells that offer programmable
Index: sysctl.c
===================================================================
RCS file: /cvs/freebsd/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.88
diff -u -r1.88 sysctl.c
--- sysctl.c    15 Oct 2007 20:00:19 -0000      1.88
+++ sysctl.c    12 May 2008 19:07:34 -0000
@@ -58,8 +58,8 @@
 #include <string.h>
 #include <unistd.h>
 
-static int     aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag;
-static int     qflag, xflag;
+static int     aflag, bflag, dflag, eflag, hflag, iflag, Nflag, nflag;
+static int     oflag, qflag, xflag;
 
 static int     oidfmt(int *, int, char *, u_int *);
 static void    parse(char *);
@@ -89,7 +89,7 @@
        setbuf(stdout,0);
        setbuf(stderr,0);
 
-       while ((ch = getopt(argc, argv, "AabdehNnoqwxX")) != -1) {
+       while ((ch = getopt(argc, argv, "AabdehiNnoqwxX")) != -1) {
                switch (ch) {
                case 'A':
                        /* compatibility */
@@ -110,6 +110,9 @@
                case 'h':
                        hflag = 1;
                        break;
+               case 'i':
+                       iflag = 1;
+                       break;
                case 'N':
                        Nflag = 1;
                        break;
@@ -185,6 +188,8 @@
        len = name2oid(bufp, mib);
 
        if (len < 0) {
+               if (iflag)
+                       return;
                if (qflag)
                        exit(1);
                else

Attachment: pgpLMDzSeAALE.pgp
Description: PGP signature

Reply via email to