[rancid] excluding output from cisco routers and switches
rdrake
rdrake at direcpath.com
Tue Jan 5 00:32:29 UTC 2016
On 01/04/2016 03:16 PM, allonon wrote:
> I wanted to start a different topic as mine is not about flash or
> bootflash.
>
> I have a similar issue with nexus output and want to prevent diff
> emails but I want the data in the the saved config. One of switches
> will constantly adjust output watts by a few points.
>
>
> !Env: ------- ------------------- ---------- ----------
> ---------- --------------
> - !Env: 1 N9K-PAC-650W-B 67 W 649 W Ok
> - !Env: 2 N9K-PAC-650W-B 71 W 649 W Ok
> + !Env: 1 N9K-PAC-650W-B 68 W 649 W Ok
> + !Env: 2 N9K-PAC-650W-B 70 W 649 W Ok
>
>
> My scripting-fu is non-existent and am trying to learn this.
>
> I figure I have 3 options.
> Just have Rancid ignore the line. (not preferred as I want to see
> the PS as OK or not)
> Filter email output.
> Filter the actual diff. (can the diff actually handle advanced
> parsing? Everything I see shows how to ignore line based on simple match)
>
> I found this snippet from another thread on how to filter email output
> but I'm getting lost on what it is doing after the first grep
> > DIFF=`cat $TMP.diff | grep -v "^===" | grep -v "^diff " | grep -v
> > "^Index: " | grep -v "^retrieving revision" | grep -v "^$"`
> > if [ -n "$DIFF" ]; then
> > ...email stuff here...
> > fi
>
> How do I best adjust this so that it greps for the ENV or N9K-PAC
> line, and ignore (not send diff email) it if the Ok is there.
>
> Thanks
>
The multiple greps in that example are for different commands they want
to match and exclude. You can do something like this:
DIFF=`cat $TMP.diff | grep -Ev "[ +-] \!Env: [0-9]"`
You can test if your regex is working by making a fake diff and seeing
if the grep matches :
[rdrake at test ~]$ cat test.in | grep -E "[ +-] \!Env: [0-9]"
- !Env: 1 N9K-PAC-650W-B 67 W 649 W Ok
- !Env: 2 N9K-PAC-650W-B 71 W 649 W Ok
+ !Env: 1 N9K-PAC-650W-B 68 W 649 W Ok
+ !Env: 2 N9K-PAC-650W-B 70 W 649 W Ok
[rdrake at test ~]$ cat test.in | grep -Ev "[ +-] \!Env: [0-9]"
!Env: ------- ------------------- ---------- ----------
---------- --------------
(if you want to get rid of this line too you can use this)
[rdrake at test ~]$ cat test.in | grep -Ev "[ +-] \!Env: [0-9-]"
[rdrake at test ~]$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20160104/4622675a/attachment.html>
More information about the Rancid-discuss
mailing list