Reachability Test
Zur Navigation springen
Zur Suche springen
Testscripte um zu testen, ob ein Server noch nach Aussen sieht oder nicht.
Diese Scripte erfordern screen:
# apt-get install screen
Init Script
Folgendes Skript nach /etc/init.d/ kopieren und ausführbar machen. /etc/init.d/reachabilitytest:
#! /bin/sh
### BEGIN INIT INFO
# Provides: reachability test
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: pings switch.ch(130.59.138.57) and metas.ch(162.23.8.239) to test the reachability
# Description: more foo for your bars
### END INIT INFO
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting reachability test"
screen -dm -S reachabilityswitch /etc/reachabilityscript_switch.sh
screen -dm -S reachabilitymetas /etc/reachabilityscript_metas.sh
;;
stop)
echo "Stopping reachability test"
screen -X -S reachabilityswitch quit
screen -X -S reachabilitymetas quit
;;
*)
echo "Usage: /etc/init.d/reachabilitytest {start|stop}"
exit 1
;;
esac
exit 0
Startscripts
Diese beiden Skripte in /etc erstellen und ausführbar machen.
/etc/reachabilityscript_switch.sh:
#!/bin/bash
host=130.59.138.57
while :; do
result=`ping -W 20 -c 1 $host | grep 'bytes from '`
if [ $? -gt 0 ]; then
echo -e "`date +'%Y/%m/%d %H:%M:%S'` - host $host is down" >> /var/log/reachability/reachability_switch.txt
else
echo -e "`date +'%Y/%m/%d %H:%M:%S'` - host $host is ok -`echo $result | cut -d ':' -f 2`" >> /var/log/reachability/reachability_switch.txt
sleep 20 # avoid ping rain
fi
done
/etc/reachabilityscript_metas.sh:
#!/bin/bash
host=162.23.8.239
while :; do
result=`ping -W 20 -c 1 $host | grep 'bytes from '`
if [ $? -gt 0 ]; then
echo -e "`date +'%Y/%m/%d %H:%M:%S'` - host $host is down" >> /var/log/reachability/reachability_switch.txt
else
echo -e "`date +'%Y/%m/%d %H:%M:%S'` - host $host is ok -`echo $result | cut -d ':' -f 2`" >> /var/log/reachability/reachability_switch.txt
sleep 20 # avoid ping rain
fi
done