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():