0

I am trying to run a script file of all of my Debian computers in my house, the script will get the /home/script file from the Master machine when I call MPI to run it on all the machines. Right now I have to go onto each machine and do this command:

sudo scp -r max@10.0.0.216:/home/scripts /home

But I want it to be run within a Python script. Here's what I've come up with:

import subprocess

subprocess.check_call(["sudo", "-S", "scp", "-r", "max@10.0.0.216:/home/scripts", "/home"])

The error is the following:

    sudo: sudono tty present and no askpass program specified:
no tty present and no askpass program specified
Traceback (most recent call last):
File "/home/scripts/Update-Scripts/script.py", line 3, in <module>
subprocess.check_call(["sudo", "scp", "-r", "max@10.0.0.216:/home/scripts", "/home"])
File "/usr/lib/python2.7/subprocess.py" line 190, in check_call
raise CalledProcessError(retcode,cmd)
subprocess.CalledProcessError: Command '['sudo', 'scp', '-r', 'max@10.0.0.216:/home/scripts', '/home']' returned non-zero exit status
Gilles Gouaillardet
  • 8,193
  • 11
  • 24
  • 30
MaxK123
  • 390
  • 3
  • 15
  • You are trying to run a command named `scp -r`, you want to split off the option as a separate argument `["scp", "-r", `... – tripleee Aug 19 '21 at 09:07
  • If you want the `sudo` you have to add that back on, too. – tripleee Aug 19 '21 at 09:08
  • Why do you want Python here, though? You are fundamentally using `scp` anyway and Python is just a worse shell than the shell for that. – tripleee Aug 19 '21 at 09:08
  • @tripleee I split the -r but now I get premission denied, and when I use sudo I get a lot of errors, I will update the main post with the new line and the errors. – MaxK123 Aug 19 '21 at 09:20
  • The error means `sudo` is not connected to a terminal so it can't ask for a password. You need to run from a place where you can supply the password interactively, or configure `sudo` to run passwordless for this command. – tripleee Aug 19 '21 at 09:30
  • Duplicate of https://stackoverflow.com/questions/26013242/cannot-sudo-su-anymore-no-tty-present-and-no-askpass-program-specified (though not the accepted answer) – tripleee Aug 19 '21 at 09:31
  • Going forward, please take care not to trample previous edits when updating your posts. – tripleee Aug 19 '21 at 09:33
  • I have made public rsa keys so I can ssh to any of my machines without password, but not with scp, should it use the same keys? – MaxK123 Aug 19 '21 at 09:35
  • `sudo` is a different program which doesn't know anything about your SSH keys; it is configured with a local configuration file. Again, please review the proposed duplicate. – tripleee Aug 19 '21 at 09:37
  • When I added -S I get the error: sudo: no password was provided, how do I provide a password? – MaxK123 Aug 19 '21 at 09:50

0 Answers0