linux cron 执行脚本后没有效果, 日志报错ORPHAN (no passwd entry)

我们在直接执行脚本是可以的,但是使用cron没有效果, 查看日志(/var/log/cron)会有ORPHAN (no passwd entry)报错

原因: 环境变量

解决方案

1、所有命令需要写成绝对路径形式,如: /usr/local/bin/docker。

2、在 shell 脚本开头使用以下代码:

#!/bin/sh

. /etc/profile
. ~/.bash_profile

3、在 /etc/crontab 中添加环境变量,在可执行命令之前添加命令 . /etc/profile;/bin/sh,使得环境变量生效,例如:

20 03 * * * . /etc/profile;/bin/sh /var/www/runoob/test.sh

参考文献: https://www.runoob.com/linux/linux-comm-crontab.html

 

原文地址:https://www.cnblogs.com/fancyblogs/p/15524204.html