mirror of
https://github.com/ARM-software/devlib.git
synced 2025-02-07 13:40:48 +00:00
Merge pull request #25 from mdigiorgio/bg-as_root
ssh: add possibility to run command in background as root
This commit is contained in:
commit
91f4f97a0b
@ -177,10 +177,12 @@ class SshConnection(object):
|
|||||||
except EOF:
|
except EOF:
|
||||||
raise TargetError('Connection lost.')
|
raise TargetError('Connection lost.')
|
||||||
|
|
||||||
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
|
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
|
||||||
try:
|
try:
|
||||||
port_string = '-p {}'.format(self.port) if self.port else ''
|
port_string = '-p {}'.format(self.port) if self.port else ''
|
||||||
keyfile_string = '-i {}'.format(self.keyfile) if self.keyfile else ''
|
keyfile_string = '-i {}'.format(self.keyfile) if self.keyfile else ''
|
||||||
|
if as_root:
|
||||||
|
command = "sudo -- sh -c '{}'".format(command)
|
||||||
command = '{} {} {} {}@{} {}'.format(ssh, keyfile_string, port_string, self.username, self.host, command)
|
command = '{} {} {} {}@{} {}'.format(ssh, keyfile_string, port_string, self.username, self.host, command)
|
||||||
logger.debug(command)
|
logger.debug(command)
|
||||||
if self.password:
|
if self.password:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user