现在的位置: 首页 > 综合 > 正文

手把手教你:Ubuntu下cron定时执行命令无法成功执行的解决方法

2018年05月18日 ⁄ 综合 ⁄ 共 273字 ⁄ 字号 评论关闭

问题:

在/etc/cron.d文件下新建test_cron文件,在该文件中写入命令:

*/1 * * * * root /home/chaoma/education/test_crond.sh

注意test_crond.sh必须为可执行文件,否则该定时执行任务执行失败。

chmod u+x test_crond.sh

注意在test_crond.sh中执行脚本时路径的问题,你写的相对路径是相对于root下的路径,因此容易出错。

采用 cd 跳转到你需要的目录下,在执行相应的命令。

比如:

cd /home/chaoma/education/

mkdir -p ./test_dir

抱歉!评论已关闭.