我需要每24小时杀死并重新启动ngrok
服务器,因此我考虑使用cronjob运行Shell脚本。我面临的问题是,当我在shell脚本中重新启动ngrok
时,它将在给定的shell会话中启动它。
如何在不同的会话中开始ngrok
,以便可以在同一脚本中继续进行其他检查?
我到目前为止的代码:
# grabs the PID for the current running ngrok
ngrok_pid=$(pgrep ngrok)
echo "Current ngrok PID = ${ngrok_pid}"
# kills ngrok
kill_ngrok_pid=$(kill -9 $ngrok_pid)
# get exit status code for last command
check=$?
# check if the exit status returned success
if [ $check -eq 0 ]; then
# re-start ngrok
$(./ngrok http 5000 &)
# do more checks below...
else
echo "NO ngrok PID found"
fi