python from fabric import Connection, exceptions def execute_remote_command(): try: conn = Connection('remote_host') result = conn.run('command_to_execute') if result.ok: print('Command executed successfully') else: print('Command failed with exit code: {}'.format(result.exited)) except exceptions.ConnectionError: print('Unable to connect to remote host') except exceptions.CommandTimeout: print('Command execution timed out') except exceptions.GroupException as e: for ex in e.exceptions: print('Command failed on host {}: {}'.format(ex.connection.host, ex)) execute_remote_command()


上一篇:
下一篇:
切换中文