python-Cron Bash:无法使用 cron 运行 bash 文件
发布时间:2022-08-29 11:53:39 266
相关标签: # node.js
我有一个从 pipenv 环境运行的 Python 脚本。
我想使用 cron 每分钟运行一次,但我没有成功,我能找到的解决方案对我不起作用。
首先我试过:
* * * * * cd /home/santiago/flaskpostgres/writeText && pipenv run python3 main.py
但我什么都没有。
我试着搜索一个解决方案,有几个地方推荐了一个bash文件,所以我把这行代码改为
* * * * * bash /home/santiago/hello.sh
并编写了一个名为hello的bash文件。包含的sh
#! usr/bin/bash
cd /home/santiago/flaskpostgres/writeText
pipenv run python3 main.py
我还更改了hello的权限。sh带
chmod +x hello.sh
但也没什么。
bash文件本身就可以工作,我已经单独进行了测试,但cron似乎没有运行它。
当我使用这一行进行测试时,cron确实可以工作
* * * * * echo "hello" >> /tmp/test.txt
这没有问题,它只是这个我无法工作的python文件
如果它有帮助,位于 flaskpostgres/writeText/main.py 的 python 文件的内容是:
from datetime import datetime
with open('sample.txt', 'a') as file_object:
# Append 'hello' at the end of file
file_object.write(f"{datetime.now()} \n")
# Close the file
file_object.close()
这有点像一个伪python文件,我想安排的是一个真正的python文件,它有一些复杂的副作用,所以我不能每次想测试cron时都运行它。
服务器正在运行Ubuntu 20.04.3
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报