crontab 环境变量

最近执行定时上传文件时,发现总时上传失败。定时任务 0 2 * * * sh /home/smart_push/ftp_upload_log/uploadlog.sh 1 >/dev/null 2>&1,手动执行很正常。查看日志也正常。

一筹莫展之时,输入mail命令,发现显示 lzop: command not found。手动可以执行,说明环境变量配置正确,同时表明crontab没有加载系统环境变量。百度发现crontab的确不会加载用户环境变量。

解决方案,在脚本中引入环境变量。

#方法一:通过source导入
source /etc/profile
source ~/.bash_profile
#方法二:直接执行系统脚本
. /etc/profile
. ~/.bash_profile

猜你喜欢

转载自tcspecial.iteye.com/blog/2233284
今日推荐