osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

python3 subprocess run sudo cmd in remote failed


>
> Well, there's a Python library called "paramiko" which implements ssh.
> That might help.
>
> Later I will try lol.


> Note also that since stdin and stdout are pipes and not the terminal
> then ssh will not be interactive, and will not allocate a tty at the far
> end either. You can get ssh to open a remote tty with the -t option.
>
> But I suspect you don't want stdin=PIPE or stdout=PIPE at all. Why are
> they there?
>
> I thought I can use ps.stdin.write(password), so I make stdin and stdout
be pipe as input and output.

Here are I tried:
>from subprocess import Popen, PIPE
>ps = Popen('ssh -o \'StrictHostKeyChecking no\' hello at 192.168.80.11 \'sudo
sysctl -w vm.drop_caches=3\', shell=True)
>  hello at 192.168.80.11's password:

>from subprocess import Popen, PIPE
>ps = Popen(['ssh',  '-o \'StrictHostKeyChecking no\'',  '
hello at 192.168.80.11', '\'sudo sysctl -w vm.drop_caches=3\''])
>  hello at 192.168.80.11's password:

It always prompt immediately, that make me hard to enter password.
 Maybe I should try  paramiko...