mwilliamson / spur.py

Run commands and manipulate files locally or over SSH using the same interface
BSD 2-Clause "Simplified" License
267 stars 37 forks source link

Unable to do sudo su using shell.run? #59

Closed aligajani closed 7 years ago

mwilliamson commented 7 years ago

I'll need a few more details to be able to understand your issue. What code are you using? What results are you seeing? What results do you expect?

aligajani commented 7 years ago

shell.run(["sudo", "su"], cwd = dir, encoding="utf-8")

When I run that, the script hangs indefinitely.

I want to be switching user to root so I can do stuff on my remote server.

mwilliamson commented 7 years ago

It might be waiting for you to enter a password. What happens when you run the command yourself?

You can also try capturing the stdout and stderr when you run the command.

mwilliamson commented 7 years ago

Actually, come to think of it, wouldn't running su cause a new shell (as in a new Bash process or whatever you're using) to be spawned, so it's waiting for user input (in the case that you don't need to enter a password)?

aligajani commented 7 years ago

When I run it myself on the server, it works.

aligajani commented 7 years ago

How would I make this work with Spur ? I wish to login as root and do stuff.

mwilliamson commented 7 years ago

I would suggest prepending sudo to each command you want to run.

aligajani commented 7 years ago

No, that doesn't work. I need to do sudo su to get myself as in root. I originally login as ubuntu. I can't login as root either as ec2 servers have a problem.

mwilliamson commented 7 years ago

Why doesn't using sudo on the individual commands work, especially if you expect sudo su to work?

You can use sudo su if you want, but that means you'll have to work out how to interact with the shell. Specifically, you'll have to use spawn() and send appropriate strings into the stdin of the process, and parse the output of the shell (if you want to read the output of any of your commands).

aligajani commented 7 years ago

I just did sudo su && cp /var/lib/redis/dump.rdb /home/ubuntu/ and it didn't copy.

I did this from the actual server not local. It just logged in as root. No error returned either.

mwilliamson commented 7 years ago

I think you want to run sudo cp /var/lib/redis/dump.rdb /home/ubuntu/.

aligajani commented 7 years ago

Thank you. Yes.

I ran this now sudo su -c 'cp /var/lib/redis/dump.rdb /home/ubuntu/'.

Works.