I read some similar topics but no luck to fix my issue.
This is my first Python script, it runs no problem when I manually execute it.
But it doesn't work with below crontab.
0,15,30,45 * * * * /usr/bin/python /usr/lib/python3.5/venv/send_email_attachment.py >/dev/null 2>&1
I also try to below.
*/2 * * * * /usr/bin/python /usr/lib/python3.5/venv/send_email_attachment.py > /tmp/listener.log >/dev/null 2>&1
The listener.log is generated but empty.
Any idea? Thanks
The form of a cronjob is:
* * * * * user-name command to be executed
You forgot to add the user which runs the cronjob. Supposing you run it using the root user, change the code to:
*/2 * * * * root /usr/bin/python /usr/lib/python3.5/venv/send_email_attachment.py > /tmp/listener.log >/dev/null 2>&1
Run this command: sudo /etc/init.d/cron restart
after setting crontab demon has to restart
Reference: Run a python script from with arguments (from argparse in python) from crontab
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.