python字符串方法,os调用系统命令方法整理,远程链接服务器执行命令

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 命令 +本地文件路径 + 用户名@服务器域名:服务器上存放的文件路径

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值