Remote Service DFU Modus Wartung: Unterschied zwischen den Versionen
Erscheinungsbild
Keine Bearbeitungszusammenfassung |
|||
| (2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 41: | Zeile 41: | ||
#!/bin/bash | #!/bin/bash | ||
for i in $(wget -O- -q https://wetter.zeber.li/wartung/01.txt) | for i in $(wget -O- -q --no-check-certificate https://wetter.zeber.li/wartung/01.txt) | ||
do | do | ||
PORT=7401 | PORT=7401 | ||
| Zeile 55: | Zeile 55: | ||
echo $$ > ${LOCKFILE} | echo $$ > ${LOCKFILE} | ||
#ssh -R 19999:localhost:22 simon@rz.zeberliedv.ch -p "5984" | #ssh -R 19999:localhost:22 simon@rz.zeberliedv.ch -p "5984" | ||
/usr/bin/ssh -p 5984 -fNC -R $PORT:localhost:22 | /usr/bin/ssh -p 5984 -fNC -R $PORT:localhost:22 www-data@backup-zeberliedv.ch | ||
# do stuff | # do stuff | ||
sleep 1000 | sleep 1000 | ||
| Zeile 71: | Zeile 71: | ||
Cronjob: | Cronjob: | ||
*/1 * * * * /bin/sh /home/weewx/wartung/ssh_run.sh | */1 * * * * /bin/sh /home/weewx/wartung/ssh_run.sh | ||
==Python PushOver Script für wartung== | |||
<syntaxhighlight lang="python"> | |||
#!/usr/bin/env python | |||
import httplib, urllib | |||
from subprocess import call | |||
import os | |||
# Application specific variables | |||
application_token = "a5pkftw8x5cmed64qa3ecyod9e6txz" #Wartung | |||
user_token = "uqsV4ZLmM8q7FjgtbjzyXrUZHheLdx" #Simon | |||
# Message specific variables | |||
title = "Logger.01 Wartung (SupportID=7501)" | |||
message = (os.popen("hostname -I").read(), " https://logger.zeber.li/01/admin.php ") | |||
url = "https://logger.zeber.li/logger/01" | |||
# To remove any of these fields you will need to remove them | |||
# from the conn.request() below | |||
# Start your connection with the Pushover API server | |||
conn = httplib.HTTPSConnection("api.pushover.net:443") | |||
# Send a POST request in urlencoded json | |||
conn.request("POST", "/1/messages.json", | |||
urllib.urlencode({ | |||
"token": application_token, | |||
"user": user_token, | |||
"title": title, | |||
"message": message, | |||
"url": url, | |||
}), { "Content-type": "application/x-www-form-urlencoded" }) | |||
# Listen for any error messages or other responses | |||
conn.getresponse() | |||
</syntaxhighlight> | |||
Aktuelle Version vom 27. November 2021, 10:28 Uhr
Liste der ID von Geräten und Ports
Rückverbindung
ssh localhost -p 19999
Create Key
ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub simon@rz.zeberliedv.ch -p "5984"
Alternative:
cat ~/.ssh/id_rsa.pub | ssh simon@rz.zeberliedv.ch -p "5984" "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
open tunnel
ssh -R 19999:localhost:22 simon@rz.zeberliedv.ch -p "5984"
Testing
ssh -p '5984' 'simon@rz.zeberliedv.ch'
Rückverbindung
ssh localhost -p 19999
Installation
Auto SSH installieren
sudo apt-get install autossh
SSH Konfig als Gateway
sudo nano /etc/ssh/sshd_config ClientAliveInterval 3 ClientAliveCountMax 9 GatewayPorts yes AllowTcpForwarding yes
Wartungs Script
nano /home/weewx/wartung/ssh_run.sh
Datei Ausführbar machen:
chmod +x ssh_run.sh
Wartung:
#!/bin/bash
for i in $(wget -O- -q --no-check-certificate https://wetter.zeber.li/wartung/01.txt)
do
PORT=7401
LOCKFILE=/home/weewx/wartung/wartungsmodus.lock
if [ "$i" = "1" ]; then
echo "Wartungsmodus ist $i"
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "already running"
exit
fi
# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
#ssh -R 19999:localhost:22 simon@rz.zeberliedv.ch -p "5984"
/usr/bin/ssh -p 5984 -fNC -R $PORT:localhost:22 www-data@backup-zeberliedv.ch
# do stuff
sleep 1000
rm -f ${LOCKFILE}
else
echo "Wartungsmodus ist $i"
rm -f ${LOCKFILE}
#Alle SSH Verbindungen Trennen
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
#ps -ef | grep sshd | grep -v root | grep -v 12345 | grep -v grep | awk '{print "sudo kill -9", $2}' |sh
fi
done
Cronjob:
*/1 * * * * /bin/sh /home/weewx/wartung/ssh_run.sh
Python PushOver Script für wartung
#!/usr/bin/env python
import httplib, urllib
from subprocess import call
import os
# Application specific variables
application_token = "a5pkftw8x5cmed64qa3ecyod9e6txz" #Wartung
user_token = "uqsV4ZLmM8q7FjgtbjzyXrUZHheLdx" #Simon
# Message specific variables
title = "Logger.01 Wartung (SupportID=7501)"
message = (os.popen("hostname -I").read(), " https://logger.zeber.li/01/admin.php ")
url = "https://logger.zeber.li/logger/01"
# To remove any of these fields you will need to remove them
# from the conn.request() below
# Start your connection with the Pushover API server
conn = httplib.HTTPSConnection("api.pushover.net:443")
# Send a POST request in urlencoded json
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": application_token,
"user": user_token,
"title": title,
"message": message,
"url": url,
}), { "Content-type": "application/x-www-form-urlencoded" })
# Listen for any error messages or other responses
conn.getresponse()