I have the following files
lb_status_switch_int.txt
switch0.3021
switch0.3022
switch0.3023
switch0.3029
showiproute.txt
IP Route Table for VRF "default"
S *> 0.0.0.0/0 [1/0] is directly connected, pppoe1
S 0.0.0.0/0 [2/0] via 172.16.21.1, switch0.3021
S 0.0.0.0/0 [4/0] via 172.16.22.1, switch0.3022
S 0.0.0.0/0 [210/0] via 172.16.22.15, switch0.3022
S 0.0.0.0/0 [7/0] via 172.16.29.1, switch0.3029
S 0.0.0.0/0 [6/0] via 172.16.23.1, switch0.3023
and the following code
#!/bin/bash
INTF[$i]=switch0.3022
function InterfaceIP () {
function Vartemdist () {
if [[ ${TMINTSW[$e]} == switch0.3* ]]
then temdist=$(awk '/'${TMINTSW[$e]}'/{for(i=1;i<=NF;i++)if($i=="0.0.0.0/0")print substr($(i+1), 2, length($(i+1)) - 4)} ' showiproute.txt) ; else : ; fi
temdist=$(echo $temdist | awk 'END {print min}{min || min=$1;$1<min && min=NR}')}
function SwitchInterfaces () {
intswitch=$(awk '{if(NR=='$m') print $1}' lb_status_switch_int.txt)
function VarIntIP () {
if [[ ${INTF[$i]} == switch0.3* ]] && ((${TMDIST[$e]} < '210'))
then intip=$(awk '/'${INTF[$i]}'/{gsub(",","",$(NF-1));for(i=1;i<=NF;i++)if($i=="via")print $(i+1)}' showiproute.txt) ;else : ; fi}
Dq=$(cat lb_status_switch_int.txt | wc -l)
m=0
for e in $(seq $Dq); do
m=$(( $m + 1 ))
SwitchInterfaces $e
TMINTSW[$e]=${intswitch}
Vartemdist $e
TMDIST[$e]=${temdist}
VarIntIP $e
done
echo -e TMINTSW=${TMINTSW[$e]}
echo -e intswitch=$intswitch
echo -e temdist=$temdist
echo -e 'intip='$intip'\n'
}
InterfaceIP
and I'm getting the following output
TMINTSW=switch0.3029
intswitch=switch0.3029
temdist=7
intip=172.16.22.1 172.16.22.15
My problem is that my intip variable takes two values and I want to take only the one with the lowest temdist number (4) so that the output is the following
TMINTSW=switch0.3029
intswitch=switch0.3029
temdist=7
intip=172.16.22.1
Can someone tell me what I'm doing wrong?
Aucun commentaire:
Enregistrer un commentaire