Cron(cronie)抛出语法错误,但手动工作

时间:2019-10-23 09:05:18

标签: python sqlite cron

这是我第一次尝试使用cron,我希望它从数据库中提取数据,如果满足条件,则返回某些信息。我正在将烧瓶与sqlalchemy一起使用。

曾经在网上搜索并发现了类似的错误,但对我来说却不可行。

import sqlite3
import datetime

connection = sqlite3.connect('sms_agenda/users.db')
cursor = connection.cursor()
cursor.execute("SELECT phone, timezone FROM user;")
result = cursor.fetchall()
now = datetime.datetime.utcnow()
now_str = str(now)[11:13]
for phone, timezone in result:
    if int(now_str) + int(timezone) == 20:
        print(phone)

cursor.close()
connection.close()

输入systemctl status cronie返回:

okt 23 10:58:01 qq88-pc CROND[30858]: (root) CMDOUT (import: unable to open X server `' @ error/import.c/ImportImageCommand/343.)
okt 23 10:58:01 qq88-pc CROND[30857]: (qq88) CMDOUT (import: unable to open X server `' @ error/import.c/ImportImageCommand/343.)
okt 23 10:58:01 qq88-pc CROND[30858]: (root) CMDOUT (import: unable to open X server `' @ error/import.c/ImportImageCommand/343.)
okt 23 10:58:01 qq88-pc CROND[30858]: (root) CMDOUT (/home/qq88/python-virtual-environments/sms/check_send.py: line 6: syntax error near unexpected token `(')
okt 23 10:58:01 qq88-pc CROND[30858]: (root) CMDOUT (/home/qq88/python-virtual-environments/sms/check_send.py: line 6: `connection = sqlite3.connect('sms_agenda/users.db')')
okt 23 10:58:01 qq88-pc CROND[30858]: pam_unix(crond:session): session closed for user root
okt 23 10:58:01 qq88-pc CROND[30857]: (qq88) CMDOUT (import: unable to open X server `' @ error/import.c/ImportImageCommand/343.)
okt 23 10:58:01 qq88-pc CROND[30857]: (qq88) CMDOUT (/home/qq88/python-virtual-environments/sms/check_send.py: line 6: syntax error near unexpected token `(')
okt 23 10:58:01 qq88-pc CROND[30857]: (qq88) CMDOUT (/home/qq88/python-virtual-environments/sms/check_send.py: line 6: `connection = sqlite3.connect('sms_agenda/users.db')')
okt 23 10:58:01 qq88-pc CROND[30857]: pam_unix(crond:session): session closed for user qq88

这就是我进入cron的时间:

* * * * * /home/qq88/python-virtual-environments/sms/check_send.py

仅供参考,这是通过Twilio发送短信,但为了进行测试,我只希望它打印手机。

1 个答案:

答案 0 :(得分:0)

尝试像这样

* * * * * /usr/bin/python3 /home/qq88/python-virtual-environments/sms/check_send.py