亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

paramiko 遠程遠程部署軟件腳本案例

發布時間:2020-07-26 17:01:20 來源:網絡 閱讀:225 作者:dengwang123 欄目:系統運維


paramiko 遠程遠程部署軟件腳本案例


#?-*-?coding:?utf-8?-*-

import?paramiko
import?sys,?os
import?datetime
import?subprocess
import?time
import?re
import?hashlib

reload(sys)
sys.setdefaultencoding("utf-8")
os.environ["PATH"]?=?"/usr/local/jdk18/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
os.environ["LANG"]?=?"en_US.UTF-8"

ip_list?=?["10.110.189.217","10.110.193.106"]


class?pub_filebeat():

????def?__init__(self):
????????self.username?=?"redis"
????????self.passwd?=?"123456"
????????self.client_ssh?=?None
????????self.sftpcliet?=?None
????????self.port?=?22
????????self.chan?=?None
????????self.result?=?None


????#?創建一個ssh?鏈接
????def?create_ssh(self,ip):
????????self.client_ssh?=?paramiko.SSHClient()
????????self.client_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
????????self.client_ssh.connect(ip,?self.port,?self.username,?self.passwd,?timeout=5)
????????self.chan?=?self.client_ssh.invoke_shell()
????????self.flag=None
????????'''?
????????在現有的ssh鏈接的基礎上獲取一個ftp鏈接
????????方式一???:
????????transport?=?self.client_ssh.get_transport()
????????self.sftpcliet?=?paramiko.SFTPClient.from_transport(transport)
????????
????????方式二?:
????????self.sftpcliet?=?self.client_ssh.open_sftp()
????????'''
????????#
????????#?transport?=?self.client_ssh.get_transport()
????????#?self.sftpcliet?=?paramiko.SFTPClient.from_transport(transport)
????????self.sftpcliet?=?self.client_ssh.open_sftp()

????def?execute(self,ip):
????????try:
????????????self.sendcmd("?sudo?su?-?")
????????????if?self.flag?==?1:
????????????????self.sendcmd("redis@yto369")
????????????self.sendcmd("?cd?/home/redis?")
????????????self.sendcmd("?tar??-zxvf?filebeat623.tar.gz?")
????????????self.sendcmd("?sed?-i?'s/hostip:?10.1.241.99/hostip:?%s/g'?filebeat623/filebeat.yml?;?"?%?(ip))
????????????self.sendcmd("?nohup?filebeat623/filebeat?-e??-c?filebeat623/filebeat.yml?>?info.log?2>&1?&?")
????????????print?"%s?filebeat?部署完成"?%?(ip)
????????except?Exception,e:
????????????print?e.message


????def?tranfile(self):
????????try:
????????????self.sftpcliet.put("F:\dwchaoyue\ELK\/filebeat623.tar.gz",?'/home/redis/filebeat623.tar.gz')
????????except?Exception,e:
????????????print?e.message
????????????self.sftpcliet.close()


????def?sendcmd(self,cmd):
????????cmd?=?cmd?+?'\r'
????????p?=?re.compile(r'\[root@.+\s.*\]')
????????self.result?=?""
????????self.chan.send(cmd)
????????while?True:
????????????time.sleep(0.5)
????????????ret?=?self.chan.recv(65535).decode("utf-8")
????????????self.result?=?self.result?+?ret
????????????if??'password'?in?self.result.split("?"):
????????????????self.flag?=?1
????????????????break
????????????if?p.search(ret):
????????????????break


????#?遍歷ip?列表
????def?bianli(self,ip_list):
????????for?ip?in?ip_list:
????????????self.create_ssh(ip)
????????????if?self.check_result()?>=?1?:
????????????????print?"%s?filebeat?已部署,無需重新部署"?%?(ip)
????????????????continue
????????????????pass
????????????self.tranfile()
????????????self.execute(ip)
????????????if?self.check_result()?<?1:
????????????????print?"%s?filebeat?部署失敗?,請重試"?%?(ip)
????????????self.client_ssh.close()
????????????self.sftpcliet.close()


????def?check_result(self):
????????std_in,std_out,std_err?=?self.client_ssh.exec_command("ps??-ef??|?grep??-i?filebeat?|?grep??-v??'grep'?|?wc??-l")
????????return?int(std_out.read())


if?__name__?==?"__main__":
????try:
????????pb?=?pub_filebeat()
????????pb.bianli(ip_list)
????except?Exception,?e:
????????print?e


paramiko 遠程執行命令和上傳下載代碼案例

Phttps://www.cnblogs.com/haigege/p/5513759.html

phttps://blog.csdn.net/a382486075/article/details/78658165


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

邮箱| 丁青县| 玉林市| 柳江县| 土默特右旗| 云林县| 延川县| 师宗县| 金川县| 五河县| 新绛县| 新野县| 南康市| 丽江市| 威宁| 明光市| 绥江县| 霞浦县| 保山市| 巴林右旗| 建德市| 全州县| 定陶县| 普安县| 绥阳县| 通海县| 台江县| 揭西县| 临朐县| 双峰县| 乐陵市| 绩溪县| 峨山| 隆昌县| 滨海县| 大名县| 论坛| 丹寨县| 长岭县| 高雄市| 云梦县|