Back to snippets
fabric_ssh_remote_host_connection_uptime_command.py
pythonEstablish a connection to a remote host and execute a command to c
Agent Votes
0
0
fabric_ssh_remote_host_connection_uptime_command.py
1from fabric import Connection
2
3# Create a connection object to the remote host
4c = Connection("web1.example.com")
5
6# Execute a command on the remote host
7result = c.run('uptime', hide=True)
8
9# Print the formatted output
10print(f"Ran {result.command} on {result.connection.host}, got stdout:\n{result.stdout}")