fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] Fabric 2.4.0 problem - Run method is not being finished


From: Brandon Whaley
Subject: Re: [Fab-user] Fabric 2.4.0 problem - Run method is not being finished
Date: Fri, 28 Dec 2018 17:32:13 -0500

You might be able to use su's -c parameter to run each command
individually, so try something like this:

command_template = "su -c '{}'"
command = command_template.format("ls /root")
print("Response on {} is: {}".format(command, dss.run(command,
pty=False, watchers=[sudopass])))

Just be careful not to format any commands with single quotes, that
won't escape them.  There's probably a smarter way to do this but I've
not needed to use it in fabric2 yet.

On Fri, Dec 28, 2018 at 5:17 PM Mateusz <address@hidden> wrote:
>
> Hi There,
>
> I'm trying to use fabric library to control subprocesson on linux device. 
> I've prepared a piece of code, which intention is to log as a root user.
> I can't use "sudo" method because that is not existing on the system that i 
> want to control. Also logging directly as "root" is impossible. My idea is to 
> log as a "admin" user and then use "su" command to switch to "root" user.
>
> Code:
>
> from fabric import Connection
> from invoke import Responder
>
> sudopass = Responder(pattern=r'Password:', response='adminPassword\n')
>
> with Connection('192.168.0.106', user="admin", port=22, 
> connect_kwargs={"password": "admin"}) as dss:
>     command = "uname -s"
>     print("Response on {} is: {}".format(command, dss.run(command)))
>     command = "whoami"
>     print("Response on {} is: {}".format(command, dss.run(command)))
>     command = "su"
>     print("Response on {} is after executing su command: {}".format(command,
>                                                                     
> dss.run(command, pty=True, watchers=[sudopass])))
>     command = "whoami"
>     print("Response on {} is: {}".format(command, dss.run(command)))
> print("Script end")
>
> Output:
>
> Linux
> Response on uname -s is: Command exited with status 0.
> === stdout ===
> Linux
>
> (no stderr)
> dssadmin
> Response on whoami is: Command exited with status 0.
> === stdout ===
> dssadmin
>
> (no stderr)
> Password:
> /home/dssadmin #
>
> As you can see script got stuck after sending "su" command. Any ideas how to 
> solve that?
>
> I'm using:
> Python 3.7
> Fabric 2.4.0
>
>
> Thanks in advance
>
> Mateusz Glowinski
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user



reply via email to

[Prev in Thread] Current Thread [Next in Thread]