crontab /etc/profile.d

DD.*_*DD. 4 linux profile cron

我有一个 crontab 脚本,它在交互式 shell 中运行良好。但是,当从 crontab 运行时,它会失败,因为它没有运行 /etc/profile.d/ 中的脚本(例如 /etc/profile.d/java.sh)

解决这个问题的最佳方法是什么?

DD.*_*DD. 6

使用以下命令开始 shell 脚本:

#!/bin/bash -l
Run Code Online (Sandbox Code Playgroud)

这会导致 bash 作为登录 shell 启动,这意味着它将读取 /etc/profile 和 ~/.bash_profile。

  • 要在 SLES 中使用这个想法,必须在 crontab 中指定`11 11 * * * /bin/bash -l -exec "some && commands"`。 (4认同)