Benutzerspezifische Werkzeuge
Sie sind hier: Startseite Dokumente bash.sh
Artikelaktionen

bash.sh

von BeDaZuletzt verändert: 04.05.2008 21:45

MRTG Shell Script

Hier klicken, um die Datei herunterzuladen

Größe: 3.2 kB - Dateityp text/x-sh

Dateiinhalt

#!/bin/sh

TYPE=$1
PARAM=$2

if [ "$TYPE" = "load" ]; then
   INDATA=`cat /proc/loadavg | cut -d " " -f2 | sed "s/\.//g" | sed "s/^0*//g"`
   OUTDATA=`cat /proc/loadavg | cut -d " " -f3 | sed "s/\.//g" | sed "s/^0*//g"`
fi

if [ "$TYPE" = "processes" ]; then
   INDATA=`cat /proc/loadavg | cut -d " " -f4 | cut -d "/" -f2`
   OUTDATA=`cat /proc/loadavg | cut -d " " -f4 | cut -d "/" -f1`
fi

if [ "$TYPE" = "network" ]; then
   TEMP=`cat /proc/net/dev | grep $PARAM | sed "s/$PARAM://"`
   INDATA=`echo $TEMP | awk '{print $1}'`
   OUTDATA=`echo $TEMP | awk '{print $9}'`
fi

if [ "$TYPE" = "mem" ]; then
   INDATA=`cat /proc/meminfo  | grep "MemTotal:" | sed 's/ \+/ /g' | cut -d " " -f2`
   OUTDATA=`cat /proc/meminfo | grep "^Active:" | sed 's/ \+/ /g' | cut -d " " -f2`
fi

if [ "$TYPE" = "swap" ]; then
   INDATA=`cat /proc/meminfo | grep "SwapTotal:" | sed 's/ \+/ /g' | cut -d " " -f2`
   OUTDATA=`cat /proc/meminfo | grep "SwapCached:" | sed 's/ \+/ /g' | cut -d " " -f2`
fi

if [ "$TYPE" = "uptime" ]; then
   INDATA=`cat /proc/uptime | cut -d " " -f1`
   OUTDATA=`cat /proc/uptime | cut -d " " -f2`
fi

if [ "$TYPE" = "tcpest" ]; then
   INDATA=`netstat -atn | grep -c ESTABLISHED`
   OUTDATA=$INDATA
fi

if [ "$TYPE" = "users" ]; then
   INDATA=`users | wc -w`
   OUTDATA=$INDATA
fi

if [ "$TYPE" = "mail" ]; then
   INDATA=`cat /var/log/exim4/mainlog | grep '=>' | grep -c -E '(virtual_delivery|local_delivery)'`
   OUTDATA=`cat /var/log/exim4/mainlog | grep '=>' | grep -c -E -v '(virtual_delivery|local_delivery|ditch_)'`
fi

if [ "$TYPE" = "reject" ]; then
   INDATA=`cat /var/log/exim4/mainlog | grep -c -E '(rejected RCPT|rejected EHLO)'`
   OUTDATA=`cat /var/log/exim4/mainlog | grep -E -v '(rejected RCPT|rejected EHLO)' | grep -c rejected`
fi

if [ "$TYPE" = "teamspeak" ]; then
   INDATA=`printf "sel 8767\npl\nquit\n" | netcat localhost 51234 | grep -c "^[0-9]"`
   OUTDATA=$INDATA
fi

if [ "$TYPE" = "teamspeak_traffic" ]; then
   INDATA=`printf "sel 8767\nsi\nquit\n" | netcat localhost 51234 | grep "server_bytesreceived" | cut -d "=" -f2`
   OUTDATA=`printf "sel 8767\nsi\nquit\n" | netcat localhost 51234 | grep "server_bytessend" | cut -d "=" -f2`
fi

if [ "$TYPE" = "temp" ]; then
   INDATA=`snmpwalk -v 1 -c public beda.dyndns.org .1.3.6.1.4.1.2021.8 | grep UCD-SNMP-MIB::extOutput.1 | sed "s/UCD-SNMP-MIB::extOutput.1 = STRING: //g"`
   OUTDATA=$INDATA
fi

if [ "$TYPE" = "hddtemp" ]; then
   INDATA=`/usr/sbin/hddtemp  -n /dev/sda`
   OUTDATA=`/usr/sbin/hddtemp  -n /dev/sdb`
fi

if [ "$TYPE" = "ntpjitterdelay" ]; then
   INDATA=`/usr/bin/ntpq -p | grep "^*" | tr -s ' ' |cut -d' ' -f8 | sed "s/\.//"`
   OUTDATA=`/usr/bin/ntpq -p | grep "^*" | tr -s ' ' |cut -d' ' -f10 | sed "s/\.//"`
fi

if [ "$TYPE" = "ntpoffset" ]; then
   INDATA=`/usr/bin/ntpq -p | grep "^*" | tr -s ' ' |cut -d' ' -f9 | sed "s/\.//"`
   OUTDATA=`/usr/bin/ntpq -p | grep "^*" | tr -s ' ' |cut -d' ' -f9 | sed "s/\.//"`
fi

if [ "$TYPE" = "ntppackets" ]; then
   INDATA=`/usr/bin/ntpdc -c iostats | grep "received packets" | cut -d ":" -f2`
   OUTDATA=`/usr/bin/ntpdc -c iostats | grep "packets sent" | cut -d ":" -f2`
fi

echo $INDATA
echo $OUTDATA
echo `uptime | cut -d "," -f1,2`
echo $TYPE