Linux cron has no effect after executing the script, and the log reports an error orphan (no passwd entry)

We can execute the script directly, but using cron has no effect. If you check the log (/ var/log/cron), an error will be reported by orphan (no passwd entry)

Reason: environment variable


1. All commands need to be written in absolute path form, such as:/usr/local/bin/docker.

2. Use the following code at the beginning of the shell script:


. /etc/profile
. ~/.bash_profile

3. Add environment variables in/etc/crontab, and add the command./etc/profile before the executable command/ Bin/sh to make the environment variable effective, for example:

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

“21442;” “32771;”


Similar Posts: