【发布时间】:2017-07-25 17:06:37
【问题描述】:
我尝试在 crontab 中运行 schedule.sh(shell 脚本)
这是脚本中的代码
#!/bin/sh -x
SHELL=/bin/bash
PATH=/home/peteryph/bin:/home/peteryph/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
python3 main_schedule.py
echo "Finish"
在 crontab 终端中(crontab -e)
* * * * * /home/peteryph/Desktop/working/city_google/schedule.sh > /home/peteryph/Desktop/working/city_google/echo2.txt
* * * * * /usr/bin/python3 /home/peteryph/Desktop/working/city_google /schedule.py > /home/peteryph/Desktop/working/city_google/echo.txt
处于 cron 状态
(peteryph) CMD (/home/peteryph/Desktop/working/city_google/schedule.sh > /home/peteryph/Desktop/working/city_google/echo2.txt)
(peteryph) CMD (/usr/bin/python3 /home/peteryph/Desktop/working/city_google /schedule.py > /home/peteryph/Desktop/working/city_google/echo.txt)
在main_schedule中,代码是这样的
(我确实导入了文件。它们很多,所以我没有把它们放在这里。)
print("Please wait.........\n")
infor = update()
infor.clear_previous_value() #update the data in the DB
start_time = time.time()
infor.select_update() #insert the data into DB
print("Running time --%s seonds--" %(time.time() - start_time) + "\n")
sys.exit()
我尝试同时执行 python 文件和脚本,但我只收到来自 python 文件的回显。但是数据没有在 crontab 上的 python 文件和脚本上插入数据库。
但是,当我手动执行脚本时,它可以工作。
(我的文件中确实有非英文字符,这会影响 crontab 吗?)
(或者数据库的路径必须是绝对路径?)
【问题讨论】:
标签: python-3.x sqlite cron