Created
December 1, 2012 14:17
-
-
Save morgaine/4182524 to your computer and use it in GitHub Desktop.
Example snippet showing use of shell to display ping status on LEDs
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 | |
LED_CONTROL_CMD="switch_led" | |
LED_CONTROL_CMD="echo" | |
BASE_LED_NUMBER="5" | |
INTERVAL="30" | |
HOSTS=" | |
google.com | |
slashdot.org | |
no-such-host.net | |
" | |
while true | |
do | |
LED_NO="$BASE_LED_NUMBER" | |
for TARGET in $HOSTS | |
do | |
if ping -n -c 1 $TARGET >/dev/null 2>&1 | |
then | |
"$LED_CONTROL_CMD" "$LED_NO" 1 | |
else | |
"$LED_CONTROL_CMD" "$LED_NO" 0 | |
fi | |
LED_NO=$(($LED_NO + 1)) | |
done | |
sleep "$INTERVAL" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I think somebody already should have found complete solution for this. I am also doing a project in which I required similar functionality but couldn't figure out how it will be done. Please post the complete solution. Thank you very much.