建模程序 多个定时程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
987 B

import paramiko,time,sys
def main_optimize_model(pid):
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 = f'nohup seg_python /data/code/optimize_model_xj/optimize_model.py -pid {pid} >{pid}.log 2>&1&'
stdin, stdout, stderr = ssh.exec_command(command)
# 打印命令是否启动成功
print("Command executed")
finally:
# 确保连接被关闭
if ssh:
time.sleep(1)
ssh.close()
if __name__ == '__main__':
if len(sys.argv) == 2:
pid = sys.argv[1]
main_optimize_model(pid)