1.通过connection连接远程主机,并执行命令
python
from fabric import connection
con1 = connection.Connection(host='10.10.102.198', user='root', port=22, connect_kwargs={"password":"HC@Cloud2022CN"})
con1.run('free -h')
2.上传压缩文件到主机指定目录下,并解压
python
con1.put('test.tar.gz', '/root/dockerfile/svn2git/fabric')
con1.run('tar -zxvf /root/dockerfile/svn2git/fabric/test.tar.gz -C /root/dockerfile/svn2git/fabric/')
con1.run('ls /root/dockerfile/svn2git/fabric')
3.从目标服务器跳转到另一台服务器,pty=True
python
con1.run('ssh root@10.10.102.148',pty=True)