Hello awk experts:
I need your help. I am new in awk and I need to do a script in awk that make follows:
Taking this output:
...
!
address-family ipv4
neighbor 148.223.23.65 activate
neighbor 148.223.23.65 send-community
neighbor 148.223.23.65 remove-private-as
neighbor 148.223.23.65 route-map AXTEL-IN in
neighbor 148.223.23.65 route-map AXTEL-OUT out
neighbor 201.117.10.141 activate
neighbor 201.117.10.141 send-community
neighbor 201.117.10.141 remove-private-as
neighbor 201.117.10.141 route-map PROTEL-IN in
neighbor 201.117.10.141 route-map PROTEL-OUT out
neighbor 201.117.10.141 maximum-prefix 1000 restart 1
neighbor 201.125.74.109 activate
neighbor 201.125.74.109 send-community
neighbor 201.125.74.109 remove-private-as
neighbor 201.125.74.109 route-map MARCATEL-IN in
neighbor 201.125.74.109 route-map MARCATEL-OUT out
neighbor 201.125.74.109 maximum-prefix 1000 restart 1
exit-address-family
!
...
I need to do an awk script that shows in a table the follows:
Peer IP address maximum-prefix configured
Axtel 148.223.23.65 No
Protel 201.117.10.141 Yes
Marcatel 201.125.74.109 Yes
Then this output needs to be sent by email and implemented with crontab, could you please help me? I was thinking in using records and arrays to implement this awk script, but I started to study awk and it is difficult for me.
Sponsored by: █ Sparkhost - Hosting Without Compromises! █ Hybrid Performance Web Hosting █ Spark Host Stream Hosting █ Hybrid IRC & IRCd Server Shell Accounts
awk script
Started by
julawk
, Jun 07 2008 07:45 PM
1 reply to this topic
#1
Posted 07 June 2008 - 07:45 PM
#2
Posted 08 June 2008 - 01:21 AM
if the filename with these data is "input_file" then the following bash/shell script will work fine. Maybe it's not the perfect solution but it works 
Shell Script
-------------
Output
--------
Then you can use mail command... it's up to you.
Have a nice day
Shell Script
-------------
#!/bin/bash
ips=`cat input_file | awk -F " " '{print$2}' | grep "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$" | sort | uniq`
for ip in ${ips[@]}; do
name=`cat input_file | grep "$ip.* in" | awk -F " " '{print $4}' | sed 's/-IN$//g'`
res=`cat input_file | grep $ip.*maximum-prefix`
if [[ -n $res ]]
then
echo $name $ip "Yes"
else
echo $name $ip "No"
fi
doneOutput
--------
AXTEL 148.223.23.65 No PROTEL 201.117.10.141 Yes MARCATEL 201.125.74.109 Yes
Then you can use mail command... it's up to you.
Have a nice day
when a hungry man comes to ask your help, do not give him a fish, rather teach him how to catch a fish
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












