23 lines
737 B
Python
23 lines
737 B
Python
import paramiko
|
|
|
|
try:
|
|
# 创建SSH对象
|
|
ssh = paramiko.SSHClient()
|
|
# 允许连接不在known_hosts文件中的主机
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
print('start connect')
|
|
# 连接服务器
|
|
ssh.connect('connect.bjc1.seetacloud.com', username='root', password='QoQA8q3Ds2VB', port=33733)
|
|
print('connect success')
|
|
|
|
# 使用nohup执行命令,并将输出重定向到文件
|
|
command = 'nohup seg_python /data/code/optimize_model_xj/optimize_model.py -pid 189813 > output.log 2>&1 &'
|
|
stdin, stdout, stderr = ssh.exec_command(command)
|
|
|
|
# 打印命令是否启动成功
|
|
print("Command executed")
|
|
finally:
|
|
# 确保连接被关闭
|
|
if ssh:
|
|
ssh.close()
|