无法使用cron每隔5分钟运行一次python脚本
我用-e选项编辑了crontab。然后我转到/etc/cron.d目录,创建一个文件来运行该进程。我再次编辑/etc/crontab文件。但我没能让它跑起来。我从stackoverflow中引用了这个,做了完全相同的事情,但我不知道为什么cron不为我工作? 下面是我的crontab的样子-无法使用cron每隔5分钟运行一次python脚本,cron,Cron,我用-e选项编辑了crontab。然后我转到/etc/cron.d目录,创建一个文件来运行该进程。我再次编辑/etc/crontab文件。但我没能让它跑起来。我从stackoverflow中引用了这个,做了完全相同的事情,但我不知道为什么cron不为我工作? 下面是我的crontab的样子- # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through
# 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
*/5 * * * * anikde /home/anikde/Documents/pythonProjects/python_scripts/*
* * * * * anikde python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py
我已将第一个作业设置为每5分钟运行一次,将第二个作业设置为每1分钟运行一次。但没有一个作业是自动运行的。当我命令作业以bash脚本的形式运行第一个脚本,以python脚本的形式运行第二个文件时,它们实际上会运行。我假设您正在尝试每隔5分钟自动运行以下脚本:
/home/anikde/Documents/pythonProjects/python_scripts/test/write.py
首先,使用哪个Python
命令确定Python可执行文件的位置。在下面的示例中,我假设返回的路径是/usr/bin/python
crontab-e
),请尝试以下命令:*/5 * * * * anikde /usr/bin/python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py
sudo crontab-e
)我假设您正在尝试每5分钟自动运行以下脚本:
/home/anikde/Documents/pythonProjects/python_scripts/test/write.py
首先,使用哪个Python
命令确定Python可执行文件的位置。在下面的示例中,我假设返回的路径是/usr/bin/python
crontab-e
),请尝试以下命令:*/5 * * * * anikde /usr/bin/python /home/anikde/Documents/pythonProjects/python_scripts/test/write.py
sudo crontab-e
)您不需要在/etc/crontab中手动创建文件。只需使用
crontab-e
编辑cron,相关的cron文件就会更新。我这样做了,但脚本不会自动运行。我实际上正在考虑再次安装cron,它会有帮助吗。检查您的crontab计划是否正确(crontab条目中的前5列)。这是正确的。你可以尝试不同的价值观。只要从其他合适的值开始。检查您的命令是否在没有cron的情况下运行。你能手动运行吗。编辑您的帖子,并包含您的确切crontab。或者将其包含在评论中。很难猜出什么是错误的。您不需要在/etc/crontab中手动创建文件。只需使用crontab-e
编辑cron,相关的cron文件就会更新。我这样做了,但脚本不会自动运行。我实际上正在考虑再次安装cron,它会有帮助吗。检查您的crontab计划是否正确(crontab条目中的前5列)。这是正确的。你可以尝试不同的价值观。只要从其他合适的值开始。检查您的命令是否在没有cron的情况下运行。你能手动运行吗。编辑您的帖子,并包含您的确切crontab。或者将其包含在评论中。很难猜出什么是错的。非常感谢卡齐姆。这就是为什么我喜欢linux社区和开源产品。我很高兴它起了作用。非常感谢KazikM。这就是为什么我喜欢linux社区和开源产品。我很高兴它奏效了。