Networker

Re: [Networker] Client Listing

2007-07-23 17:31:34
Subject: Re: [Networker] Client Listing
From: Darren Dunham <ddunham AT TAOS DOT COM>
To: NETWORKER AT LISTSERV.TEMPLE DOT EDU
Date: Mon, 23 Jul 2007 14:26:37 -0700
> Hi all, I am looking to pull a client list from Networker using NSRADMIN
> and all I want is the client name and the comment fields.  I can get
> this running without issue, but the dump from nsradmin, in it's
> multi-line format is almost completely useless for manipulation in
> Excel.  Anyone know of an easy way to get this in a comma delimited
> format?  BTW, I am running on windows (just in case someone has some
> fancy script I might not be able to run).

You can run perl on windows (but you'll probably have to download it).
I'm afraid my VB skills are rather limited.

Here's an example.  You'd need to change the path to your nsradmin
binary on your system.  (Even on Windows, I recommend using forward
slashes (/) instead of backslashes (\) for the file components.  They
work just as well, and they don't have to be escaped.)

Also, you say *the* client name and comment fields.  You can have
multiple client instances, each with different comments.  This script
does no organization of the data, but just prints it.  Since you're
trying to put it in Excel, you can do the sorting or whatever in there. 

#!/usr/bin/perl
use strict;
use warnings;

use IPC::Open2;

my $nsradmin = '/usr/sbin/nsradmin';

my ($rdr, $wtr);
my $pid = open2($rdr, $wtr, $nsradmin, '-i', '-');

print $wtr "show name;comment\n";
print $wtr "print type:nsr client\n";
close $wtr;

my $client;
while(<$rdr>)
{
  chomp;
  if (s/\\$//) # ends in backslash
    { 
      $_ .= <$rdr>;
      chomp;
      redo;
    }
  if (/name\:\s*(.*);/) { $client = $1; next; }
  if (/comment\:\s*(.*);/) { print "$client,$1\n"; }
}

Enjoy!

-- 
Darren Dunham                                           ddunham AT taos DOT com
Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

To sign off this list, send email to listserv AT listserv.temple DOT edu and 
type "signoff networker" in the body of the email. Please write to 
networker-request AT listserv.temple DOT edu if you have any problems with this 
list. You can access the archives at 
http://listserv.temple.edu/archives/networker.html or
via RSS at http://listserv.temple.edu/cgi-bin/wa?RSS&L=NETWORKER