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")
2
  • 1
    can you do something like this? stackoverflow.com/questions/10310299/… Commented Aug 23, 2017 at 15:07
  • yes thanks to the sudo -t ! Commented Aug 23, 2017 at 18:45

1 Answer 1

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'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.