1

I need to run a deamon over a remote Linux machine, using SSH.

Deamon's name is pigpiod and it belongs to pigpio module ( controling Raspberry Pi's GPIO ), Ubuntu Mate 16.04.

Executing commands that does not require sudo (for example- ls)- script runs OK, while those who need sudo, fails.

adress='192.168.2.112' , is a remote Linux to run this daemon.

Code below fails (running sudo pigpiod):

def runpigpiod_remote(adress):
    result = subprocess.run(['ssh','guy@'+adress,'sudo','pigpiod'])

Code below succeeds(run ls -l)

def runpigpiod_remote(adress):
    result = subprocess.run(['ssh','guy@'+adress,'ls','-l'])

In order the check if subprocess.run capable of executing sudo+ command - I tryied localy on same machine and it succeeds:

def run_process():
    try:
        check_output(["pidof","pigpiod"])
        print("pigpiod already loaded")
    except:
        subprocess.CalledProcessError
        print("Not Loaded")
        subprocess.run(['sudo','pigpiod'])
        if os.system("pgrep -x "+name)==0:
            print("Loaded successfully")
guyd
  • 693
  • 2
  • 14
  • 32

1 Answers1

2

Code changed ( thanks to comment of @Hamuel )- as noted in proper way to sudo over ssh

def runpigpiod_remote(adress):
    result = subprocess.run(['ssh','-t','guy@'+adress,'sudo','pigpiod'])
guyd
  • 693
  • 2
  • 14
  • 32