fabric学习

 1.通过connection连接远程主机,并执行命令

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.上传压缩文件到主机指定目录下,并解压

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

con1.run('ssh [email protected]',pty=True)

你可能感兴趣的:(fabric,学习,python)