Python Forum
Fabric - Run method is not being finished
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fabric - Run method is not being finished
#1
Hi There,
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 and 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:
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? Thanks for help in advance:)

===========================================================================
Python 3.7
Fabric 2.4.0
Reply


Messages In This Thread
Fabric - Run method is not being finished - by mglowinski93 - Dec-28-2018, 05:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Process finished with exit code 137 (interrupted by signal 9: SIGKILL) erdemath 2 9,521 Apr-18-2022, 08:40 PM
Last Post: erdemath
  Using .hdf5 files only once they are finished writing pyhill00 7 2,787 Nov-25-2021, 06:01 PM
Last Post: pyhill00
  How to check if a file has finished being written leocsmith 2 7,826 Apr-14-2021, 04:21 PM
Last Post: perfringo
  process finished with exit code -1073741819 (0xC0000005) GMCobraz 8 5,401 Sep-01-2020, 08:19 AM
Last Post: GMCobraz
  How to stop Xmodem after bin file transfer was finished shaya2103 0 2,501 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 8,470 Apr-05-2019, 12:46 PM
Last Post: mrazko
  Progress Finished Question malonn 32 17,474 May-23-2018, 02:43 AM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020