Last active
August 29, 2015 14:06
-
-
Save Nama/75946516f857088d720a to your computer and use it in GitHub Desktop.
Sends TCP Pakets to the TCP Server. Turns on lights if Computer is reachable, off if not reachable. lights_state.sh syncs the states of the lights, so the lights are turned on on next day. Avoids turning off or on if you manually turned on or off the lights.Used with crontab.
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 | |
/usr/local/bin/ping -c 1 192.168.1.2 | |
ec=$? | |
state=`cat /root/light2_state` | |
stat=`echo -e "licht 2 status" | nc 192.168.1.3 54321` | |
s=$((${#stat}-1)) | |
stat=${stat:$s:1} | |
echo "nc: $stat" | |
echo "file: $state" | |
if [ "$stat" -eq "$state" ]; then | |
if [ $ec -eq 0 ]; then | |
echo -e "licht 2 an" | nc 192.168.1.3 54321 | |
echo "1" > /root/light2_state | |
else | |
echo -e "licht 2 aus" | nc 192.168.1.3 54321 | |
echo "0" > /root/light2_state | |
fi | |
fi | |
state=`cat /root/light3_state` | |
stat=`echo -e "licht 3 status" | nc 192.168.1.3 54321` | |
s=$((${#stat}-1)) | |
stat=${stat:$s:1} | |
echo "nc: $stat" | |
echo "file: $state" | |
if [ "$stat" == "$state" ]; then | |
if [ $ec -eq 0 ]; then | |
echo -e "licht 3 an" | nc 192.168.1.3 54321 | |
echo "1" > /root/light3_state | |
else | |
echo -e "licht 3 aus" | nc 192.168.1.3 54321 | |
echo "0" > /root/light3_state | |
fi | |
fi |
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 | |
state2=`echo -e "licht 2 status" | nc 192.168.1.3 54321` | |
state3=`echo -e "licht 3 status" | nc 192.168.1.3 54321` | |
s2=$((${#state2}-1)) | |
s3=$((${#state3}-1)) | |
echo ${state2:$s2:1} > /root/light2_state | |
echo ${state3:$s3:1} > /root/light3_state |
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
59 18 * * * /root/lights_state.sh | |
*/10 0-2,19-23 * * * /root/lights.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment