Created
January 9, 2020 01:04
-
-
Save ayourtch/3add33c5dd61c40ecc8fc12e81d98f42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# A little naive probe script for RaspberryPI | |
# Written by Andrew Yourtchenko (ayourtch@gmail.com) | |
# public domain | |
# | |
# | |
# Save this file as "/usr/local/bin/run-probe" | |
# Add "/usr/local/bin/run-probe &" to your /etc/rc.local, before the "exit 0" line | |
# | |
# also create the file /etc/probe-targets with the following content: | |
# (obviously replacing the doc addresses with real ones) | |
# | |
# PROBE_TARGET4=192.0.2.1 | |
# PROBE_TARGET6=2001:db8::1 | |
# | |
. /etc/probe-targets | |
while true; do | |
# send the clear screen sequence | |
clear >/tmp/devtty0 | |
# hostname + current time | |
echo $(hostname) === $(date) >>/tmp/devtty0 | |
# all of non-link-local IP addresses | |
hostname -I >>/tmp/devtty0 | |
# errors on the ethernet interface | |
ifconfig eth0 | grep errors >>/tmp/devtty0 | |
# link-local info with some surgery to remove uninteresting data | |
sudo ethtool eth0 \ | |
| tail -n +15 \ | |
| egrep -v "Wake|Secure|Current mes|Trans|Auto|drv|MII" \ | |
| sed -e 's/ //' \ | |
| sed -e 's/Link partner advertised link modes:/Partner adv. modes:/' \ | |
>>/tmp/devtty0 | |
# show lldp/cdp neighbors that we see | |
lldpcli show neighbors | grep -v -- '------' >>/tmp/devtty0 | |
# flood-ping IPv4 default gateway and the probe host | |
DEFGW4=$(/sbin/ip -4 route | awk '/default/ { print $3 }') | |
if [ "x$DEFGW4" != "x" ]; then | |
ping -w 1 -l 64 -c 1 -i 0.1 $DEFGW4 | grep -A 5 statistics \ | |
| sed -e "s/packet/pkt/" -e "s/transmitted/tx/" -e "s/received/rx/g" -e "s/rtt //g" \ | |
>> /tmp/devtty0 | |
ping -w 1 -l 64 -c 1 -i 0.1 $PROBE_TARGET4 | grep -A 5 statistics \ | |
| sed -e "s/packet/pkt/" -e "s/transmitted/tx/" -e "s/received/rx/g" -e "s/rtt //g" \ | |
>> /tmp/devtty0 | |
else | |
echo "NO IPv4 DEFAULT GATEWAY" >>/tmp/devtty0 | |
fi | |
# flood-ping IPv6 default gateway and the probe host | |
DEFGW6=$(ip -6 route | awk '/default/ { printf "%s%%%s",$3,$5 }') | |
if [ "x$DEFGW6" != "x" ]; then | |
ping -w 1 -l 64 -c 1 -i 0.1 $DEFGW6 | grep -A 5 statistics \ | |
| sed -e "s/packet/pkt/" -e "s/transmitted/tx/" -e "s/received/rx/g" -e "s/rtt //g" \ | |
>> /tmp/devtty0 | |
ping -w 1 -l 64 -c 1 -i 0.1 $PROBE_TARGET6 | grep -A 5 statistics \ | |
| sed -e "s/packet/pkt/" -e "s/transmitted/tx/" -e "s/received/rx/g" -e "s/rtt //g" \ | |
>> /tmp/devtty0 | |
else | |
echo "NO IPv6 DEFAULT GATEWAY" >>/tmp/devtty0 | |
fi | |
# show the output to the user | |
cat /tmp/devtty0 >/dev/tty0 | |
# wait a bit | |
sleep 1 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment