os.popen办法能够获取到返回内容
HeadText = os.popen('sed -n 1p \"{}\"'.format(DirFile)).read()
os.system办法执行运行命令
Command="sh /home/TradeInfo/new/trade_plan/py/CopyTradeplan.sh" os.system(Command)
python调用ssh命令
#!/usr/bin/python3import osKeyFile = "/root/.ssh/id_rsa" # 客户端的私钥,不论哪一端生成私钥和公钥,客户端领有私钥,服务器是公钥# 你想一下是不是git让你生成私钥和公钥,而后让你把公钥粘贴过来,所以通常状况下服务器都是公钥,私钥客户端保存def check_server_df(host, port, username, pkey, command): try: data = os.popen('ssh -p {} -i {} {}@{} {}'.format(port, pkey, username, host, command)).read() except Exception as e: print(e) return dataprint (check_server_df("192.168.10.215", "22", "root", KeyFile, "date"))
由好买网提供 更多建站及源码交易信息请见 GoodMai 好买网