Networker

Re: [Networker] nsradmin with shell script

2013-06-16 12:04:51
Subject: Re: [Networker] nsradmin with shell script
From: jee <jee AT ERESMAS DOT NET>
To: NETWORKER AT LISTSERV.TEMPLE DOT EDU
Date: Sun, 16 Jun 2013 16:58:02 +0100
Try this.   It works fine with ksh, sh and bash



COMMAND
-------

nsradmin -i - <<EOF | nsrfilter.sh 
. type: NSR client
show name; client id
EOF

FILTER ("nsrfilter.sh:")
------

# nsrfilter.sh: remove escaped new lines
#
# use tr to handle the '\n' character
# use sed for substitution of more than one character
# Note: there are no spaces after the '\' at the end of each line.

#1  mask '\n'
tr -s "\n" "@" |\
#2  remove the protected newline (currently '\' + '@') from the "client id" line
#   to join both lines
sed 's/\\@//g' |\
#3  put the '\n' character back in place
tr -s "@" "\n" |\
#4  replace the nsradmin record separator ';' with a newline 
tr -s ";" "\n" |\
# remove leading characters (optional)
sed 's/^ *//'


The above filter could be written as a one-liner and add it to the nsradmin 
line after the pipe but it looks a bit long.

nsradmin -i - <<EOF | tr -s "\n" "@" | sed 's/\\@//g' | tr -s "@" "\n" | tr -s 
";" "\n" | sed 's/^ *//'
. type: NSR client
show name; client id
EOF


notes: 
- your mail client may translate some character codes -- do not copy/paste)
- I used '@' to temporarily "protect" the newline and it should work in this 
case but if you use the filter to handle other nsradmin output containing '@' 
symbols you will need to edit the filter and use a different character (e.g. 
the vertical bar '|')  



  
jee


On Thursday 13 Jun 2013 19:05:34 bangrn wrote:
> Hi ,
> 
> 
> 
> when I run below command from shell scripting and out put to a file,
> 
> 
> 
> (echo :show name;comment";echo "p type:nsrclient;Storage Nodes:xxxxx") |
> nsradmin -i  - >> /tmp/clientlist
> 
> 
> 
> the $less /tmp/clientlist shows below output as an example:
> 
> 
> 
> name:xxxxxxx;
> 
> client id: \
> ca3c9a8a-00000004-4e6e6100-4e6e60ff-00010c00-e28f8f29;
> 
> 
> Question:
> 
> 
> 
> How would I get below output instead of the above? I need to display client
> id in one line by removing the '\'; is this something to increase the
> display bufferring in the nsradmin?
> 
> 
> 
> name:xxxxxxxx;
> 
> client id: ca3c9a8a-00000004-4e6e6100-4e6e60ff-00010c00-e28f8f29; ;
> 
> 
> 
> thanks in advance
> 
> +----------------------------------------------------------------------
> 
> |This was sent by naga.bangaru AT citec.com DOT au via Backup Central.
> |Forward SPAM to abuse AT backupcentral DOT com.
> 
> +----------------------------------------------------------------------