参考来源:http://www.tennfy.com/3088.html

 

问题:

我在crontab中添加了一条定时任务

0 8 * * * sh test.sh

出乎意料的是,该定时任务并没有执行。可是我直接在shell中手动执行是没有问题的。

 

原因:

缺少环境变量导致。在shell中执行时是能够找到环境变量的,但是在crontab中,它是不会自己导入环境变量的,需要我们指定。并将所有路径都写成绝对路径。

 

解决:

0 8 * * * . /etc/profile; /bin/sh /home/abc/test.sh 

前面 . /etc/profile 就是导入环境变量

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-06
  • 2021-07-14
  • 2021-04-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2022-02-06
  • 2022-01-14
  • 2022-12-23
  • 2021-07-25
  • 2021-10-02
  • 2022-01-16
相关资源
相似解决方案