Created
October 25, 2017 17:06
-
-
Save vladbabii/2775bad7a66f087665afede3734e29d2 to your computer and use it in GitHub Desktop.
Check socat for zwave
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/bash | |
LOCALPORT=/dev/zwave | |
REMOTEPORT=10.11.12.222:7676 | |
TIMEWAIT=10 | |
echo "checking socat..." | |
if [[ $(ps ax | grep -v grep | grep tcp:$REMOTEPORT | wc -l) -eq 0 ]] | |
then | |
echo " ... restarting" | |
/usr/bin/socat pty,link=$LOCALPORT,raw,group=root,mode=777 tcp:$REMOTEPORT & | |
echo " ... command sent" | |
sleep 2 | |
else | |
echo " ... running" | |
fi | |
echo "checking status..." | |
STATUS=$(netstat -an | grep 10.11.12.222:7676 | awk '{print $6}') | |
echo " ... status - $STATUS" | |
if [[ $STATUS == "ESTABLISHED" ]] | |
then | |
echo " ... all ok, exiting" | |
exit 0 | |
else | |
echo " ... waiting for $TIMEWAIT seconds" | |
STATUS=$(netstat -an | grep 10.11.12.222:7676 | awk '{print $6}') | |
echo " ... status - $STATUS" | |
if [[ $STATUS == "ESTABLISHED" ]] | |
then | |
echo " ... all ok" | |
exit 0 | |
else | |
echo " ... connection failed, killing socat" | |
kill -9 $(pidof socat) | |
if [[ $(ps ax | grep -v grep | grep tcp:$REMOTEPORT | wc -l) -eq 0 ]] | |
then | |
echo " ... all killed" | |
exit 0 | |
else | |
echo " ... error killing!" | |
exit 1 | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment