a='{}'.format('123')
print(a)
#'123'
a='1,2,3'
print(a.replace(',',''))
#'123'
#运行系统命令并打印运行结果
os.popen('lsof -i:{}'.format(self.appium_port)).readlines()
a=os.system(ls)
print(a)
#0成功,1失败,2错误
远程链接服务器执行脚本命令
import paramiko as paramiko
from threading import Thread
import time
#@asynca可异步执行,不加装饰器同步
def asynca(f):
def wrapper(*args, **kwargs):
thr = Thread(target=f, args=args, kwargs=kwargs)
thr.start()
return wrapper
class Remote_link_mac_exec_command:
def get_pid(self,port):
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='xxx.xxx.xx.x', port=22, username='hamzsy', password='123456', compress=True)
stdin, stdout, stderr = ssh.exec_command('lsof -i:{}'.format(port))
time.sleep(3)
pid = stdout.read().decode().split(' ')[12].split(' ')[0]
ssh.close()
return pid
def kill_appium(self,port):
pid = self.get_pid(port)
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='xxx.xxx.xx.x', port=22, username='hamzsy', password='123456', compress=True)
stdin, stdout, stderr = ssh.exec_command('kill -9 {}'.format(pid))
time.sleep(3)
value_kill = stdout.read().decode()
ssh.close()
return value_kill
@asynca
def run_appium(self,appium_port):
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='172.16.5.200', port=22, username='hamzsy', password='123456', compress=True)
stdin, stdout, stderr = ssh.exec_command('bash --login -c "nohup appium -p {} &"'.format(appium_port))
time.sleep(3)
return stderr.read().decode()
@asynca
def edit_appium(self, devices_name,text_value):
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='xxx.xxx.xx.x', port=22, username='hamzsy', password='123456', compress=True)
stdin, stdout, stderr = ssh.exec_command('bash --login -c "adb -s {} shell input text "{}"&"'.format(devices_name,text_value))
time.sleep(3)
return stderr.read().decode()
mac远程发送文件
上传文件到远程服务器:scp 命令 +本地文件路径 + 用户名@服务器域名:服务器上存放的文件路径