python自动发布-优化版本
作者:互联网
import sys import time import os import paramiko from pygments.lexers import shell baseconfig = { "ip": ", "port": , "username": "", "password": "“, "localjar": "", "remotedir": "/w/","package":1 } if(baseconfig["package"] == 1): print("===========开始打包===========") os.system('mvn package -Dmaven.compile.fork=true -T 1C -Dmaven.test.skip=true') print("===========打包完成===========") localjar = baseconfig["localjar"] jarpath = sys.path[0] + "/target/" + localjar ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=baseconfig["ip"], port=baseconfig["port"], username=baseconfig["username"], password=baseconfig["password"]) ssh.get_transport() sftp = paramiko.SFTPClient.from_transport(ssh.get_transport()) remotedir = baseconfig["remotedir"] sftp.put(jarpath, remotedir + localjar) print("===========上传成功===========") # 如果命令间有依赖关系,即 前一个命令执行成功才接着执行第二个命令,那么用cmd1 && cmd2 # 如果命令间无任何依赖关系,简单地顺序执行即可,那么用cmd1; cmd2 shell = "cd %s;source /root/.bash_profile && ./run.sh" % (remotedir) stdin, stdout, stderr = ssh.exec_command(shell) print("===========重启成功===========")
标签:remotedir,baseconfig,python,优化,ssh,版本,import,localjar,paramiko 来源: https://www.cnblogs.com/wujf/p/16371442.html