【发布时间】:2021-04-03 22:53:13
【问题描述】:
我阅读了很多其他主题并尝试了很多东西,但我仍然没有工作。
我有这个简单的 run2.sh 脚本:
#!/bin/bash
python3 my_script.py
wait;
sudo mv /home/ubuntu/test_code/csv_created_by_python_script.csv /var/www/html
当我进入目录并写入时,它工作得很好
sh run2.sh
但它不会像我想要的那样运行(每两个小时一次)。我尝试了某种 crontab,比如
* * * * * /home/ubuntu/test_code/run2.sh
* * * * * PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /home/ubuntu/test_code/run2.sh
但我认为我不明白所有这些路径的东西......
编辑:cronfile
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/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
# 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
#1 * * * * PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /home/ubuntu/test_code/run2.sh
* * * * * test_code/run2.sh &>cron.log
* * * * * pwd &>pwd.log
【问题讨论】:
-
查看
man 5 crontab,了解如何配置 cron 条目。PATH绝对不在正确的位置。 -
谢谢你,但我不得不承认我不知道如何纠正这个问题