seit Fritz!OS gibt awk ein 'segmentation fault' in mein bash script wenn ich es als zabbix ausführe...
Mit Zabbix kann ich mein Freetz monitoren.
Für die "saturation" des DSL habe ich dieses script geschrieben dass immer funktioniert hat auf 7270 und 7390
Seit Fritz!OS läuft es nicht mehr.
Die Zabbix agent darf nicht als root laufen und läuft als user zabbix.
Ein einfacher Beispiel:
root@fritz:/var/tmp# cat /sbin/adsl.saturation
Mit Zabbix kann ich mein Freetz monitoren.
Für die "saturation" des DSL habe ich dieses script geschrieben dass immer funktioniert hat auf 7270 und 7390
Seit Fritz!OS läuft es nicht mehr.
Die Zabbix agent darf nicht als root laufen und läuft als user zabbix.
Code:
root@fritz:/# sudo -u zabbix adsl.saturation rx
Segmentation fault
Segmentation fault
Segmentation fault
Segmentation fault
Segmentation fault
Segmentation fault
root@fritz:/# adsl.saturation rx
1
Ein einfacher Beispiel:
Code:
root@fritz:/var/tmp# cat test
#!/bin/sh
echo 'ab cd' | awk '{print $2}'
root@fritz:/var/tmp# ./test
cd
root@fritz:/var/tmp# sudo -u zabbix ./test
Segmentation fault
root@fritz:/var/tmp# cat /sbin/adsl.saturation
Code:
#!/bin/sh
# You do need to turn on support for %N (nanoseconds) in busybox
# the parameter rx or tx has to be given
echo "$1" | egrep -q '^(tx|rx)$' || exit 1
STATDIR=/sys/class/net/adsl/statistics
STATFILE=$1_bytes
[ -e ${STATDIR}/${STATFILE} ] || exit 1
# Create a file in /tmp to fetch the previous sample
SCRATCH=/tmp/${0##*/}.$1
# Fetch the corresponding DSL-speed of physical layer
if [ $1 = 'rx' ] ; then
showdsldstat >/var/showdsldstat
DSL_SPEED=`grep -m1 '^speed' /var/showdsldstat | awk '{print $2}' | awk -F/ '{print $1/1000}'`
else
# 'showdsldstat >/var/showdsldstat' only has to run each minute (so only in the 'rx run') ... only if the file isn't created yet (after reboot) and tx is the first, it will be called within the 'tx run'
if [ ! -e /var/showdsldstat ] ; then
sleep 3
[ -e /var/showdsldstat ] || showdsldstat >/var/showdsldstat
fi
DSL_SPEED=`grep -m1 '^speed' /var/showdsldstat | awk '{print $2}' | awk -F/ '{print $2/1000}'`
fi
# Fetch date and Bytes from ADSL-interface
NOW_TIME=`date +%s.%N`
NOW_BYTES=`cat ${STATDIR}/${STATFILE}`
# On first run, these vars do not exist
LAST_BYTES=${NOW_BYTES}
LAST_TIME=0
# read previous values
[ -f ${SCRATCH} ] && . ${SCRATCH}
# Sanity check in case previous value is somehow off
LAST_BYTES=`echo "${NOW_BYTES} ${LAST_BYTES}" | awk '{if($1 > $2) {print $2} else print $1}'`
DIFF_BYTES=`echo "${NOW_BYTES} ${LAST_BYTES}" | awk '{print $1 - $2}'`
DIFF_TIME=`echo "${NOW_TIME} ${LAST_TIME}" | awk '{print $1 - $2}'`
BITS_PER_SEC=`echo "${DIFF_BYTES} ${DIFF_TIME}" | awk '{printf"%.0f\n", 8 * $1 / $2}'`
# Write Bytes and Time to ${SCRATCH}
echo -e "LAST_BYTES=${NOW_BYTES}\nLAST_TIME=${NOW_TIME}" >${SCRATCH}
# There's some overhead going from ATM over DSL to Ethernet (PPPoA)... a bit less for PPPoE
NETTO=0.895
# grep -qi '/PPPoE' /var/showdsldstat && NETTO=0.91
# echo "${BITS_PER_SEC} ${DSL_SPEED} ${NETTO}"
RETVAL=`echo "${BITS_PER_SEC} ${DSL_SPEED} ${NETTO}" | awk '{printf"%.0f\n", $1 / ($2 * $3 * 10)}' 2>/dev/null`
[ -z '${RETVAL}' ] && RETVAL=0
echo ${RETVAL}
Zuletzt bearbeitet: