tommax
Goto Top

Python sshpass

Hallo zusammen,

ich habe ein Problem, was mich langsam zum Verzweifeln treibt ....

Ich habe 2 Raspberrys, die ich einfach pi-local und pi-remote nenne, verbunden sind sie über Wlan.
An pi-remote ist ein Relais angeschlossen. Dieses Relais soll vom pi-local, aus einem Python-Script (script.py) heraus geschaltet werden.

Wenn ich auf pi-local das Python-Script als root mit # python script.py starte dann funktioniert alles einwandfrei, das script.py startet das remotessh.sh, um eine SSH-Verbindung aufzubauen, was wiederum das relais.sh aufruft um das Relais zu aktivieren.

Das Problem ist nun, wenn ich das script.py in rc.local eintrage (/usr/bin/python /var/www/script.py) dann wird das script.py gestartet es kann aber das remotessh.sh nicht mehr ausführen, obwohl das script.py in rc.local als root gestartet wird, funktioniert das trotzdem nicht ...

Aber wenn ist das script.py als root manuell starte mit # python script.py dann läuft alles einwandfrei aber leider nicht beim Booten !?

Ich weiss nicht wo das Problem liegt, bitte um Hilfe !


script.py : (verkürzt)

dir = '/var/www'
path = os.path.join(dir, 'remotessh.sh')

from subprocess import Popen, PIPE

sh = Popen("sudo %s" % path, shell=True, stdout=PIPE, stderr=PIPE)

print sh.communicate()


Das Script remotessh.sh :
sshpass -p "geheim" ssh -o StrictHostKeyChecking=no root@pi-remote 'bash -s' < relais.sh


Das Script relais.sh :
gpio -g write 24 1
gpio export 24 in
gpio export 24 out
gpio -g write 24 0
sleep 1
gpio -g write 24 1
gpio export 24 in


Danke im Voraus!

Gruß
tom

Content-Key: 276399

Url: https://administrator.de/contentid/276399

Ausgedruckt am: 19.03.2024 um 06:03 Uhr

Mitglied: tommax
tommax 04.07.2015 um 17:17:49 Uhr
Goto Top
der 2. Link hat die Lösung gebracht face-smile

Danke!

Gruß
tom