From 991744baf1ecd524b4c7716209b90060b59857d7 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Tue, 25 Sep 2018 13:48:47 +0000 Subject: [PATCH] =?UTF-8?q?Bug=202447=20-=20les=20pages=20"cluster=20statu?= =?UTF-8?q?s"=20et=20"cluster=20user=20guide"=20affichent=20des=20quantit?= =?UTF-8?q?=C3=A9s=20de=20m=C3=A9moire=20erron=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fixed a bug : now, the displayed memory is correct even if the mem_available sge attribute returns the memory in other units than gigabyte - also, this commit includes an old improvement that makes executeCommandOn handle an optional user, which was previously slinetly ignored in the case of a local command --- Util.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Util.py b/Util.py index 908a1bd..188e615 100644 --- a/Util.py +++ b/Util.py @@ -63,21 +63,25 @@ def executeCommand(command): return result -def executeCommandOn(target_machine_fqdn, strCommand, remote_user=None): +def executeCommandOn(target_machine_fqdn, command, user=None): """ execute command on a local or remote machine (using ssh then) - :param str remote_user: + :param str user: if not None, the user that should be used to execute the command (instead of the current user) """ print("comparing %s and %s" % (getHostName(), target_machine_fqdn.split('.')[0])) if getHostName() == target_machine_fqdn.split('.')[0]: - return executeCommand(strCommand) + if user is not None: + # su -c "ls -l /tmp" graffy + return executeCommand("su -c '%s' %s" % (command, user)) + else: + return executeCommand(command) else: - if not remote_user is None: - target = '%s@%s' % (remote_user, target_machine_fqdn) + if user is not None: + target = '%s@%s' % (user, target_machine_fqdn) else: target = target_machine_fqdn - return executeProgram(['ssh', target, "%s" % strCommand]) + return executeProgram(['ssh', target, "%s" % command]) def getUpsStatus():