diff --git a/Util.py b/Util.py index 5bad141..908a1bd 100644 --- a/Util.py +++ b/Util.py @@ -63,15 +63,21 @@ def executeCommand(command): return result -def executeCommandOn(target_machine_fqdn, strCommand): +def executeCommandOn(target_machine_fqdn, strCommand, remote_user=None): """ execute command on a local or remote machine (using ssh then) + :param str remote_user: """ print("comparing %s and %s" % (getHostName(), target_machine_fqdn.split('.')[0])) if getHostName() == target_machine_fqdn.split('.')[0]: return executeCommand(strCommand) else: - return executeProgram(['ssh', target_machine_fqdn, "%s" % strCommand]) + if not remote_user is None: + target = '%s@%s' % (remote_user, target_machine_fqdn) + else: + target = target_machine_fqdn + + return executeProgram(['ssh', target, "%s" % strCommand]) def getUpsStatus():