搞了一上午, 问题很奇怪, shell写的脚本手动正常,添加到计划任务却无法正常执行, 

终于定位到问题所在

第一点 如果用cron, shell脚本中命令及文件的路径必须是绝对路径

第二点, cron的环境变量与shell不同, 所以把~/.bash_profile里面的环境变量统统写道shell脚本里, 再让cron执行就没问题了。

或者

如果你是root用户就用这个:

30 4 * * * su - root -c “/root/weblog.sh” 

如果你是非root用户就用:30 4 * * * . /etc/profile;/bin/sh  /root/weblog.sh

0  6  *  *  *  su - root -c /root/tools/backup_db.sh  >& /dev/null

 

相关文章:

  • 2021-09-01
  • 2021-08-31
  • 2021-05-24
  • 2022-02-03
  • 2021-05-06
  • 2022-01-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-12-09
  • 2021-11-13
  • 2022-01-16
  • 2022-02-09
相关资源
相似解决方案