shell 执行指定脚本内容固定时间后,杀掉进程重新启动

monitor_script.sh

#!/bin/bash
main_script="crmmq.sh"
run_time=600 # 10分钟(600秒)

while true
do
bash $main_script &
main_pid1=$!

bash $main_script &
main_pid2=$!

sleep $run_time

kill $main_pid1
wait $main_pid1 2>/dev/null

kill $main_pid2
wait $main_pid2 2>/dev/null

echo "Restarting main scripts..."
done

 

crmmq.sh

#!/bin/bash
while true
do
curl "https://xxxx/index.php?m=api&a=dealSynchronizationData" &
sleep 0.02
done