1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/bin/bash
- # 获取当前时间
- hour=`date +%H`
- minute=`date +%M`
- # 获取进程数量,一个图像处理进程,一个前端交互进程
- process_sonar=`ps -ef | grep "test_tcp.py" | grep -v grep | wc -l`
- process_sanic=`ps -ef | grep "sanic_server.py" | grep -v grep | wc -l`
- process_ws=`ps -ef | grep "ws_server.py" | grep -v grep | wc -l`
- process_count=`ps -ef | grep "count_fish_jh5_v1_bushu.py" | grep -v grep | wc -l`
- # 停止运行时间段设置
- stop_start_hour=3
- stop_start_minute=0
- stop_end_hour=3
- stop_end_minute=10
- if [[ 10#$hour -eq $stop_start_hour && 10#$minute -ge $stop_start_minute && 10#$minute -le $stop_end_minute ]]; then
- # 在 23:00 - 23:10 停止运行
- if [[ $process_sonar -gt 0 ]]; then
- ps aux | grep test_tcp.py | grep -v grep | awk '{print $2}' | xargs kill -9
- fi
- if [[ $process_ws -gt 0 ]]; then
- ps aux | grep ws_server.py | grep -v grep | awk '{print $2}' | xargs kill -9
- fi
- if [[ process_count -gt 0 ]]; then
- ps aux | grep count_fish_jh5_v1_bushu.py | grep -v grep | awk '{print $2}' | xargs kill -9
- fi
- else
- # 其余时间段运行
- if [[ process_count -eq 0 ]]; then
- cd /home/sencott/sonar/sonar_process/
- nohup /home/sencott/anaconda3/bin/python count_fish_jh5_v1_bushu.py > /home/sencott/sonar/sonar_process/log/count_fish.log 2>&1 &
- fi
- # sanic server 进程
- if [[ $process_sanic -eq 0 ]]; then
- cd /home/sencott/sonar_project/http_server
- nohup /home/sencott/anaconda3/bin/python sanic_server.py > /home/sencott/sonar/log/crontab_sanic.log 2>&1 &
- fi
- # sonar 进程
- if [[ $process_sonar -eq 0 ]]; then
- cd /home/sencott/sonar/sonar_control
- nohup /home/sencott/anaconda3/bin/python test_tcp.py > /home/sencott/sonar/log/crontab_tset_tcp.log 2>&1 &
- fi
- # ws 进程
- if [[ $process_ws -eq 0 ]]; then
- cd /home/sencott/sonar/sonar_server
- nohup /home/sencott/anaconda3/bin/python ws_server.py > /home/sencott/sonar/log/crontab_ws.log 2>&1 &
- fi
- echo "time:$hour:$minute, process_sonar:$process_sonar"
- if [[ $process_sonar -ne 7 ]]; then
- # 查找 PID 并 kill 进程
- pid=`ps -ef | grep "test_tcp.py" | grep -v grep | awk '{print $2}'`
- if [[ ! -z $pid ]]; then
- echo "kill process $pid"
- kill -9 $pid
- fi
- cd /home/sencott/sonar/sonar_control
- nohup /home/sencott/anaconda3/bin/python test_tcp.py > /home/sencott/sonar/log/crontab_tset_tcp.log 2>&1 &
- fi
- fi
- #!/bin/bash
- #获取进程数量,从服务器3个,主服务器3个
|