标签:etl inf read info popen snap orm epp ubunt

#!/usr/bin/python
# coding: utf-8
import re, os
DiamondPath = "cat /root/diamond-v1.100.0010-SNAPSHOT/diamond.yaml"
user = "ubuntu"
keyPath = "1.key"
sshCmd = "ssh -i {key} ubuntu@{ip} sudo "
PortDict = {}
result = re.findall("- ip:[ \t]*(.*)", os.popen(DiamondPath).read())
grepPort = "|grep \‘{port}\‘"
newShell = "netstat -tnlp| grep -v ‘Program‘"
for ip in result:
set01 = set()
Ip = sshCmd.format(key=keyPath,ip=ip)
print("*************" + ip + "*************")
PortNetstat = Ip + newShell
PortGrep = Ip + newShell + grepPort
ServiceNam = re.findall(".*/(.*)", os.popen(PortNetstat).read().strip())
for i in ServiceNam:
set01.add(i.strip())
setList = list(set01)
for name in range(len(setList)):
PortCmd = PortGrep.format(port=setList[name])
PortResult = list(set(re.findall(".*:(\d+)", os.popen(PortCmd).read())))
PortDict[setList[name]] = PortResult
for k, v in PortDict.items():
print(k, v)
标签:etl inf read info popen snap orm epp ubunt
原文地址:https://www.cnblogs.com/Wshile/p/13064670.html