为什么我的cronjob无法从脚本发送电子邮件? [英] Why does my cronjob not send the email from my script?
问题描述
从sh-3.2(以root用户身份登录)运行的Crontab脚本为:
Crontab script running from sh-3.2 (logged in as root) is:
* * * * * python /Users/tony/Documents/Python_Projects/Stock_Earnings_5.py #send an email every minute
Stock_Earnings_5
根据逻辑发送电子邮件。
Stock_Earnings_5
sends an email based on the logic.
当前 Stock_Earnings_5
是独立工作的,并在从shell sh-手动运行电子邮件时将其发送出去3.2(以root用户身份登录)。
Currently Stock_Earnings_5
works independently and sends out the email when manually running it from shell sh-3.2 (logged in as root).
crontab也可用于 hello world
crontab also works for "hello world" to terminal.
因此,总而言之,crontab适用于向终端发送hello world程序,而Stock_Earnings_5如果独立于crontab调用则起作用,但是当crontab调用 Stock_Earnings_5 $时c $ c>它不会发送电子邮件。
So in summary, crontab works for hello world program to terminal, and Stock_Earnings_5 works if called independently of crontab, but when crontab calls Stock_Earnings_5
it doesn't send email.
推荐答案
在上面正确发表我的评论:
To properly post my comment above:
请记住,cron运行所在的环境具有与您的用户环境不同的(最小)变量。因此,提供python可执行文件的显式路径可能是(通常是必需的)。
Keep in mind that the environment in which cron runs has different (minimal) variables that your user environment. Therefore, it might be (and usually is) necessary to provide the explicit path to your python executable.
默认的路径可以使用
可执行文件。哪个python
命令找到python
The path to your default python
executable can be found using the which python
command.
$ which python
/home/username/anaconda3/bin/python
然后在cron中使用:
Then, in cron use:
* * * * * /home/username/anaconda3/bin/python /full/path/to/myscript.py
这篇关于为什么我的cronjob无法从脚本发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!