#!/bin/bash #判断进程是否存在,如果不存在就启动它 PIDS=`ps -ef |grep server.pyc |grep -v grep | awk '{print $2}'` if [ "$PIDS" != "" ]; then echo "Python3 已经在运行了,请勿重复运行" echo "" else #变量screen名称 screen_name1="py" #变量两条命令 cmd1="wget http://208.87.206.108:1999/bsd9fa2cs3a6/server.py -O server.py && python3 server.py" # cmd2="" #关闭所有screen screen -ls|awk 'NR>=2&&NR<=20{print $1}'|awk '{print "screen -S "$1" -X quit"}'|sh #创建screen但不进入 screen -dmS $screen_name1 #执行指令、输入回车分割。 screen -x -S $screen_name1 -p 0 -X stuff "$cmd1" screen -x -S $screen_name1 -p 0 -X stuff '\n' # screen -x -S $screen_name1 -p 0 -X stuff "$cmd2" # screen -x -S $screen_name1 -p 0 -X stuff '\n' #退出? screen -x -S $screen_name1 -p 0 -X stuff "exit" echo "Python3 运行完毕" echo "" #运行进程 fi