(Simple RegExp and Junos examples)
This list is mainly for thought memorizing.
1. show interfaces in two lines list with MTU
show interfaces | match "mtu|interface:" |trim 192. show interfaces without second line with logical interface with family
before:
[edit]
user@switch# run show interfaces terse
Interface Admin Link Proto Local Remote
ge-0/0/0 up up
ge-0/0/0.0 up up eth-switch
ge-0/0/1 up up
ge-0/0/1.0 up up eth-switch
ge-0/0/2 up down
ge-0/0/2.0 up down eth-switch
... output truncated
after:
[edit]
user@switch# run show interfaces terse |except "\."
Interface Admin Link Proto Local Remote
ge-0/0/0 up up
ge-0/0/1 up up
ge-0/0/2 up down
... output truncated
3. show ipv4 address on your switch or router, show only interfaces:
{master:2}
user@switch> show interfaces terse |match "inet "
ge-0/0/12.3212 up up inet 10.32.1.41/30
ge-0/0/13.3200 up up inet 10.32.1.245/30
ge-0/0/13.3202 up up inet 10.32.1.1/30
ge-1/0/1.107 up up inet xx.yyy.zz.1/30
ge-1/0/13.3201 up up inet 10.32.1.249/30
ge-1/0/13.3203 up up inet 10.32.1.5/30
...
{master:2}
user@switch> show interfaces terse |match "inet " |trim 44
10.32.1.41/30
10.32.1.245/30
10.32.1.1/30
xx.yyy.zz.1/30
10.32.1.249/30
10.32.1.5/30
...
You could then save it to text file (add | save filename ad the end of command
show interfaces terse |match "inet " |trim 44 | save ipv4.txt
) and transfer your linux.Then do some things with it. For example calculate subnet address from ip address with ipcalc i.e.
ipcalc 10.32.1.41/30 | grep Network
...So. I did a batch file
from file like this:
10.32.1.41/30
10.32.1.245/30
to file like this:
ipcalc 10.32.1.41/30 | grep Network >> networks.out
ipcalc 10.32.1.245/30 | grep Network >> networks.out
with this two commands:
sed -e 's/^/ipcalc /' ipv4.txt > networks.sed1
sed -e 's/$/| grep Network >> networks.out/' networks.sed1 > networks.sed2
chmod a+x networks.sed1
bash networks.sed1
hopefuly gives you
10.32.1.40/30
10.32.1.244/304. just another tidily output for sflow interfaces (EX4200 Junos 10.0S10)
show interfaces terse |match "eth-switch|aenet" | match "ge|xe" | no-more
ge-0/0/0.0 up up eth-switch
ge-0/0/1.0 up up eth-switch
ge-0/0/2.0 up up eth-switch
ge-0/0/3.0 up up eth-switch
ge-0/0/4.0 up up eth-switch
ge-0/0/5.0 up up eth-switch
ge-0/0/6.0 up up eth-switch
ge-0/0/8.0 up up aenet --> ae6.0
ge-0/0/10.0 up up eth-switch
... And you need to throw it edit it with spreadsheet or via bash or something else.
Remove text after space, then add string to beginning of line.
sed 's/ .*//;s/, .*//' sflow01.txt | sed s/^/"set protocols sflow interfaces "/
No comments:
Post a Comment