首页 文章

crontab上的Shell脚本/ Python3文件

提问于
浏览
0

我尝试在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文件中的echo . 但是数据没有插入到crontab上的python文件和脚本的数据库中 .

但是,当我手动执行脚本时,脚本会起作用 .

(我的文件中有非英文字符,会影响crontab吗?)

(或者数据库的路径是否必须是绝对路径?)

1 回答

  • 0

    我找到了问题所在 .

    首先,在为sqlite3调用数据库时,必须使用数据库的绝对路径 .

    其次,确保您的shell脚本是可执行的:P

相关问题