我已经heard了,您可以检查脚本是否正在运行,如果没有,可以使用cron作业触发它。
假设我要运行的脚本是python tweepy-streaming-api.py
如何将其输入以下语法以确保脚本至少与触发cron作业一样频繁地运行?
#!/bin/bash
if [[ ! `pidof -s yourapp` ]]; then
invoke-rc.d yourapp start
fi
我不完全理解这段代码,但它似乎在检查应用程序是否正在运行,如果没有触发它。
我在运行ubuntu 14.04。
最佳答案
如果要检查.py文件,“pidof”命令将不起作用。
相反,您可以使用以下代码:
if [[ ! `ps -eaf | grep tweepy-streaming-api.py | grep -v grep` ]];then
python tweepy-streaming-api.py
fi
关于python - 如何确保脚本始终使用cron运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41665357/