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
Solution
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:
#!/bin/sh . /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/test.sh
“21442;” “32771;”https://www.runoob.com/linux/linux-comm-crontab.html
Similar Posts:
- [Solved] JSCH cannot run JAVA bash:java:Command not found.
- Linux shell script execution error: bad substitution [How to Solve]
- Solving the problem of “authentication token is no longer” in crontab
- Conversion to MySQL shell script execution error $’\ R’: command not found
- [Solved] Mac install maven Error: zsh: command not found: MVN
- How to Remove the Note: You have new mail in /var/spool/mail/root
- Shell script error newline syntax error near unexpected token
- ImportError: Couldn’t import Django [How to Solve]
- CentOS Error -bash:systemctl:command not found
- Mac ADB prompts command not found