ospf: do not repeat use of command, use variable instead with output of command

This commit is contained in:
Jérémy Dubois 2023-03-01 14:57:22 +01:00
parent ccdd16c523
commit 394b71c947
3 changed files with 11 additions and 8 deletions

View file

@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* post-install: use basename of path in generateldif.sh to define file from elsewhere * post-install: use basename of path in generateldif.sh to define file from elsewhere
* bgp, collectd, logsentry, ospf: update scripts * bgp, collectd, logsentry, ospf: update scripts
* collectd: improve dns_stats.sh script for more metrics * collectd: improve dns_stats.sh script for more metrics
* ospf: do not repeat use of command, use variable instead with output of command
### Fixed ### Fixed

View file

@ -17,6 +17,7 @@ _MAILTO="{{ ospf_mailto }}"
_TMPDIR=/tmp/check-ospf6 _TMPDIR=/tmp/check-ospf6
_PIDFILE="${_TMPDIR}"/ospf6d-check-peers.pid _PIDFILE="${_TMPDIR}"/ospf6d-check-peers.pid
ospf6_neighbor=$(/usr/sbin/ospf6ctl show neighbor)
if [ -e /etc/realname ]; then if [ -e /etc/realname ]; then
_REALNAME=$(cat /etc/realname) _REALNAME=$(cat /etc/realname)
@ -44,11 +45,11 @@ else
fi fi
# List peers and loops on them to list them and their OSPF6 state # List peers and loops on them to list them and their OSPF6 state
ospf6ctl show neighbor | grep -v "^$" | grep -v "Uptime" | awk {'print $1'} > "${_TMPDIR}"/peers-list echo "$ospf6_neighbor" | grep -v "^$" | grep -v "Uptime" | awk {'print $1'} > "${_TMPDIR}"/peers-list
while read -r _PEER while read -r _PEER
do do
_STATUS=$(/usr/sbin/ospf6ctl show neighbor | grep "${_PEER} " | awk {'print $3'}) _STATUS=$(echo "$ospf6_neighbor" | grep "${_PEER} " | awk {'print $3'})
echo -n "${_PEER}" >> "${_TMPDIR}"/ospf6-status echo -n "${_PEER}" >> "${_TMPDIR}"/ospf6-status
echo -n " " >> "${_TMPDIR}"/ospf6-status echo -n " " >> "${_TMPDIR}"/ospf6-status
if ([[ "${_STATUS}" = "FULL/BCKUP" ]] || [[ "${_STATUS}" = "FULL/DR" ]] || [[ "${_STATUS}" = "2-WAY/OTHER" ]] || [[ "${_STATUS}" = "FULL/OTHER" ]]) ; then if ([[ "${_STATUS}" = "FULL/BCKUP" ]] || [[ "${_STATUS}" = "FULL/DR" ]] || [[ "${_STATUS}" = "2-WAY/OTHER" ]] || [[ "${_STATUS}" = "FULL/OTHER" ]]) ; then
@ -81,9 +82,9 @@ do
_STATUS=$(echo "${_LINE}" | awk {'print $2'}) _STATUS=$(echo "${_LINE}" | awk {'print $2'})
_SESSION=$(echo "${_LINE}" | awk {'print $1'}) _SESSION=$(echo "${_LINE}" | awk {'print $1'})
if [[ "${_STATUS}" = "UP" ]] ; then if [[ "${_STATUS}" = "UP" ]] ; then
ospf6ctl show neighbor | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodyok echo "$ospf6_neighbor" | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodyok
else else
ospf6ctl show neighbor | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodynok echo "$ospf6_neighbor" | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodynok
fi fi
done <"${_TMPDIR}"/ospf6-status done <"${_TMPDIR}"/ospf6-status

View file

@ -17,6 +17,7 @@ _MAILTO="{{ ospf_mailto }}"
_TMPDIR=/tmp/check-ospf _TMPDIR=/tmp/check-ospf
_PIDFILE="${_TMPDIR}"/ospfd-check-peers.pid _PIDFILE="${_TMPDIR}"/ospfd-check-peers.pid
ospf_neighbor=$(/usr/sbin/ospfctl show neighbor)
if [ -e /etc/realname ]; then if [ -e /etc/realname ]; then
_REALNAME=$(cat /etc/realname) _REALNAME=$(cat /etc/realname)
@ -44,11 +45,11 @@ else
fi fi
# List peers and loops on them to list them and their OSPF state # List peers and loops on them to list them and their OSPF state
ospfctl show neighbor | grep -v "^$" | grep -v "Uptime" | awk {'print $1'} > "${_TMPDIR}"/peers-list echo "$ospf_neighbor" | grep -v "^$" | grep -v "Uptime" | awk {'print $1'} > "${_TMPDIR}"/peers-list
while read -r _PEER while read -r _PEER
do do
_STATUS=$(/usr/sbin/ospfctl show neighbor | grep "${_PEER} " | awk {'print $3'}) _STATUS=$(echo "$ospf_neighbor" | grep "${_PEER} " | awk {'print $3'})
echo -n "${_PEER}" >> "${_TMPDIR}"/ospf-status echo -n "${_PEER}" >> "${_TMPDIR}"/ospf-status
echo -n " " >> "${_TMPDIR}"/ospf-status echo -n " " >> "${_TMPDIR}"/ospf-status
if ([[ "${_STATUS}" = "FULL/BCKUP" ]] || [[ "${_STATUS}" = "FULL/DR" ]] || [[ "${_STATUS}" = "2-WAY/OTHER" ]] || [[ "${_STATUS}" = "FULL/OTHER" ]]) ; then if ([[ "${_STATUS}" = "FULL/BCKUP" ]] || [[ "${_STATUS}" = "FULL/DR" ]] || [[ "${_STATUS}" = "2-WAY/OTHER" ]] || [[ "${_STATUS}" = "FULL/OTHER" ]]) ; then
@ -81,9 +82,9 @@ do
_STATUS=$(echo "${_LINE}" | awk {'print $2'}) _STATUS=$(echo "${_LINE}" | awk {'print $2'})
_SESSION=$(echo "${_LINE}" | awk {'print $1'}) _SESSION=$(echo "${_LINE}" | awk {'print $1'})
if [[ "${_STATUS}" = "UP" ]] ; then if [[ "${_STATUS}" = "UP" ]] ; then
ospfctl show neighbor | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodyok echo "$ospf_neighbor" | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodyok
else else
ospfctl show neighbor | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodynok echo "$ospf_neighbor" | grep "${_SESSION} " {{ ospf_sed_command }} >> "${_TMPMAILDIR}"/bodynok
fi fi
done <"${_TMPDIR}"/ospf-status done <"${_TMPDIR}"/ospf-status