原因:cron的环境变量和shell脚本的环境变量不一样

解决办法:

方法一:定时任务里面切换到root执行(亲测可用)

*/5 * * * * su - root -c "/opt/test.sh"

 方法二:在脚本里面添加环境变量(未测试过)

vi /opt/tes.sh
#!/bin/bash
source /etc/profile
source ~/.bash_profile
...你的代码块

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-09-28
  • 2021-10-29
  • 2021-06-27
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-01-20
  • 2022-02-26
  • 2022-02-03
相关资源
相似解决方案