#!/bin/sh # SPDX-License-Identifier: GPL-3.0-only # # Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg debug() { (>&2 echo "nodewatcher: $1") } debug "Collecting information from batman advanced and its interfaces" if [ -f /sys/module/batman_adv/version ]; then for iface in $(batctl if | sed 's/ //'); do status=${iface##*:} iface=${iface%%:*} BATMAN_ADV_INTERFACES=$BATMAN_ADV_INTERFACES"<$iface>$iface$status" done echo -n "$BATMAN_ADV_INTERFACES" # Build a list of direct neighbors batman_adv_originators=$(/usr/sbin/batctl o -H | awk \ 'BEGIN { FS=" "; i=0 } # set the delimiter to " " { sub("\\(", "", $0) # remove parentheses sub("\\)", "", $0) sub("\\[", "", $0) sub("\\]", "", $0) sub("\\*", "", $0) sub(" ", " ", $0) o=$1".*"$1 # build a regex to find lines that contains the $1 (=originator) twice if ($0 ~ o) # filter for this regex (will remove entries without direct neighbor) { printf ""$1""$3""$4""$2""$5"" i++ } }') echo -n "$batman_adv_originators" echo -n "$(/usr/sbin/batctl gw)" batman_adv_gateway_list=$(/usr/sbin/batctl gwl -H | awk \ 'BEGIN { FS=" "; i=0 } /No gateways/ { next } { sub("\\(", "", $0) sub("\\)", "", $0) sub("\\[ *", "", $0) sub("\\]:", "", $0) sub("\\* ", "true ", $0) sub(" ", "false ", $0) printf ""$1""$2""$3""$4""$5""$6" "$7" "$8"" i++ }') echo -n "$batman_adv_gateway_list" else debug "No batman data .." exit 1 fi exit 0