我正在使用xubuntu 18.01
我有一个python程序,它刮擦天气数据并将文件保存为csv。在我使用weatherdata
授权后,它在终端中完美地运行命令chmod +x weatherdata
。
我希望这可以使用cron每两周运行一次。但是在我设置之后没有任何反应。
我正在使用NANO cron编辑器
我已经设置了cronjob尝试PATH变量,SHELL = / bin / bash /。 P把/ bin / bash放在命令前......都无济于事....
# crontab -e
SHELL=/bin/bash
MAILTO= [email protected] (removed my actual email for privacy)
PATH=/home/luke/bin/
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
34 * * * * /bin/bash /home/luke/bin/weatherdata
我希望weatherdata
python文件每小时在34分钟执行一次。
什么都没发生,我没有收到电子邮件或任何东西。
编辑:
我改为顶部
SHELL=/bin/bash
#[email protected] (commented it out)
PATH=/home/luke/bin/:/usr/sbin:/usr/bin:/sbin:/bin
运行后我得到的:15 * * * * /bin/bash /home/luke/bin/weatherdata > /tmp/weatherlog 2>&1
,如评论中所建议的那样。
Traceback (most recent call last):
File "/home/luke/Documents/Duka/Master_River_Levels_LOOP.py", line 9, in <module>
import pandas as pd
ImportError: No module named pandas
Traceback (most recent call last):
File "/home/luke/Documents/Duka/Temp_Mean_Weather_loop.py", line 9, in <module>
import pandas as pd
ImportError: No module named pandas
我需要导入一些模块来运行python脚本,第一个是panadas。
crontab -e工作看起来很好。
为什么不使用:
34 * * * * /home/luke/bin/weatherdata
或者设置一个sh文件......例如。 myfile.sh
#!/usr/local/env bash
/home/luke/bin/weatherdata
然后crontab -e读取
34 * * * * /home/luke/myfile.sh
除非你的系统管理员阻止它,否则Cron会做梦。
正如@thatotherguy所说,这是我的道路问题。
1)我在终端跑了echo $PATH
然后回来了:
/home/luke/anaconda3/bin:/home/luke/anaconda3/condabin:/home/luke/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
2)我复制并粘贴上面的路径来替换:PATH=/home/luke/bin/:/usr/sbin:/usr/bin:/sbin:/bin
with
PATH=/home/luke/anaconda3/bin:/home/luke/anaconda3/condabin:/home/luke/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
3)我将PATH=/
改为PATH=$PATH:/
现在cronjob完美地执行了。