[英]Crontab job for python script with database connection not working
First tested something simple like this, which works:首先测试了一些像这样简单的东西,它有效:
* * * * * echo "something" > /Users/sam/Desktop/vscode/crontest.txt
Now trying现在尝试
28 10 * * * /Users/user/Desktop/work/venv/bin/python /Users/user/Desktop/work/py_files/test.py
But nothing is happening.但什么也没有发生。
The python script ingests some data from API, parses JSON and outputs to a local mysql db python 脚本从 API 获取一些数据,解析 JSON 并输出到本地 mysql db
engine_insert = sqlalchemy.create_engine('mysql+pymysql://root:password@127.0.0.1:3306/database')
df.to_sql('database', engine_insert, if_exists='append', index=False)
But other simpler crons I also had issue with too like opening a website via browser so may just be a syntax issue with crontab?但是其他更简单的 cron 我也有问题,比如通过浏览器打开网站,所以可能只是 crontab 的语法问题?
I faced the same issue and I spent literally days to see where is my problem.我遇到了同样的问题,我花了几天的时间来看看我的问题在哪里。 So, try two things:所以,尝试两件事:
1- Follow these steps/instructions: https://stackoverflow.com/a/22744360/2080489 1- 按照以下步骤/说明进行操作: https : //stackoverflow.com/a/22744360/2080489
2- If you still facing the issue, try to stop any security module you have that might affect the connection. 2- 如果您仍然遇到问题,请尝试停止可能影响连接的任何安全模块。 In my case, I am using Ubuntu so I stoped AppAromr:就我而言,我使用的是 Ubuntu,所以我停止了 AppAromr:
sudo systemctl stop apparmor
or in case you want to disable it或者如果你想禁用它
sudo systemctl disable apparmor
check the app status by doing:通过执行以下操作检查应用程序状态:
sudo systemctl status apparmor
Hope this would help you.希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.