Короче, нужно мне было написать скрипт которые парсит вывод sh ip bgp. Вот сам скрипт:
#!/bin/bash
ROUTER_LIST=./routers.txt
SSHPASS=/srv/sshpass.txt
QUERY=$(echo $QUERY_STRING)
ROUTERS=$(echo $QUERY|tr '&' ' '|grep "ROUTERS"|awk '{print $1}'|tr '=' ' '|awk '{print $2}')
SUBNET=$(echo $QUERY|tr '&' ' '|grep "SUBNET"|awk '{print $2}'|tr '=' ' '|awk '{printf $2}')
ssh_request()
{
if test $ROUTERS
then
SSH_PASS=$(cat $SSHPASS|grep -F $ROUTERS|awk '{print $2}')
if test $SUBNET
then
for a in $(printf "sh ip bgp\n"|sudo -u ssh-connector sshpass -p $SSH_PASS ssh root@$ROUTERS -t vtysh 2>/dev/null|grep "*"|sed 's/ /=/'|grep "="|sed '1d'|tr '=' ' '|sed 's/*/E /'|tr '>' 'B'|grep $SUBNET|tr ' ' '=')
do
TYPE=$(echo $a|tr '=' ' '|awk '{print $1}')
GW=$(echo $a|tr '=' ' '|awk '{print $4}')
NET=$(echo $a|tr '=' ' ')
case $GW in
0.0.0.0)
AS="None"
;;
* )
AS=$(echo $a|rev|cut -f2-9 -d=|rev|tr '=' ' '|sed 's/[0-65635]//')
;;
esac
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">'
echo " <P>$TYPE<BR>"
echo " </P>"
echo '</TD>'
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">'
echo " <P>$NET<BR>"
echo ' </P>'
echo '</TD>'
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">'
echo " <P>$GW<BR>"
echo ' </P>'
echo '</TD>'
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: 1px double #808080; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm">'
echo " <P>$AS<BR>"
echo ' </P>'
echo '</TD>'
echo '</TR>'
done
else
for a in $(printf "sh ip bgp\n"|sudo -u ssh-connector sshpass -p $SSH_PASS ssh root@$ROUTERS -t vtysh 2>/dev/null|grep "*"|sed 's/ /=/'|grep "="|sed '1d'|tr '=' ' '|sed 's/*/E /'|tr '>' ' '|tr ' ' '=')
do
TYPE=$(echo $a|tr '=' ' '|awk '{print $1}')
NET=$(echo $a|tr '=' ' '|grep -F '/'|awk '{print $2}')
GW=$(echo $a|tr '=' ' '|awk '{print $3}')
case $GW in
0.0.0.0)
AS="None"
;;
[0-65535])
GW=$(echo $a|tr '=' ' '|grep -v '/'|awk '{print $2}')
;;
* )
AS=$(echo $a|rev|cut -f2-9 -d=|rev|tr '=' ' '|sed 's/[0-65635]//')
;;
esac
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">'
echo " <P>$TYPE<BR>"
echo " </P>"
echo '</TD>'
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">'
echo " <P>$NET<BR>"
echo ' </P>'
echo '</TD>'
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">'
echo " <P>$GW<BR>"
echo ' </P>'
echo '</TD>'
echo '<TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: 1px double #808080; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm">'
echo " <P>$AS<BR>"
echo ' </P>'
echo '</TD>'
echo '</TR>'
done
fi
else
true
fi
}
echo "Content-Type:text/html"
echo ""
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>'
echo '<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
<TITLE>BGP</TITLE>
<META NAME="GENERATOR" CONTENT="LibreOffice 3.5 (Linux)">
<META NAME="CREATED" CONTENT="20160430;23580900">
<META NAME="CHANGED" CONTENT="20160501;141000">
</HEAD>'
echo '<BODY LANG="ru-RU" DIR="LTR">
<P ALIGN=CENTER><FONT SIZE=5 STYLE="font-size: 20pt"><B>Просмотр
BGP-таблицы локальной сети</B></FONT></P>
<FORM NAME="FORM">'
echo ' <P>Выбирите роутер:<SELECT NAME="ROUTERS" STYLE="width: 4.37cm; height: 0.8cm; font-family: 'Liberation Sans', sans-serif; font-size: 12pt">'
for a in $(cat $ROUTER_LIST)
do
echo "<OPTION VALUE="$a">"$a""
done
echo '</OPTION>'
echo '</SELECT> Введите подсеть:<INPUT TYPE=TEXT NAME="SUBNET" SIZE=26 STYLE="width: 4.95cm; height: 0.97cm; font-family: 'Liberation Sans', sans-serif; font-size: 12pt"><INPUT TYPE=SUBMIT NAME="SEND" VALUE="OK" STYLE="width: 2.36cm; height: 0.82cm; font-family: 'Liberation Sans', sans-serif; font-size: 12pt"></P>'
echo '</FORM>'
echo '<TABLE WIDTH=100% CELLPADDING=4 CELLSPACING=1 STYLE="page-break-inside: avoid">
<COL WIDTH=64*>
<COL WIDTH=64*>
<COL WIDTH=64*>
<COL WIDTH=64*>
<TR VALIGN=TOP>
<TD WIDTH=25% STYLE="border-top: 1px double #808080; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">
<P>Тип</P>
</TD>
<TD WIDTH=25% STYLE="border-top: 1px double #808080; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">
<P>Сеть</P>
</TD>
<TD WIDTH=25% STYLE="border-top: 1px double #808080; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">
<P>Шлюз</P>
</TD>
<TD WIDTH=25% STYLE="border: 1px double #808080; padding: 0.1cm">
<P>Автономная система</P>
</TD>
</TR>
<TR VALIGN=TOP>'
ssh_request
# <TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">
# <P><BR>
# </P>
# </TD>
# <TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">
# <P><BR>
# </P>
# </TD>
# <TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm">
# <P><BR>
# </P>
# </TD>
# <TD WIDTH=25% STYLE="border-top: none; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: 1px double #808080; padding-top: 0cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0.1cm">
# <P><BR>
# </P>
# </TD>
echo ' </TR>'
echo '</TABLE>'
echo '<P><BR><BR>'
echo '</P>'
echo '</BODY>'
echo '</HTML>'
с виду скрипт работает нормально, но, как парсить вывод, если есть в sh ip bgp подсети:
1.1.1.0/24
1.1.2.1
1.1.2.2