您的位置:首页 > 其它

crontab执行脚本命令找不到

2016-03-08 00:00 183 查看
1.问题描述

一个shell脚本 shell.sh,内部使用了一个环境变量 TEST_CRONTAB_ENV=test_crontab_env
且TEST_CRONTAB_ENV存在于 /etc/profile 中
如:
#!/bin/bash
echo "`date +%Y-%m-%d" "%H:%M:%S` $TEST_CRONTAB_ENV" >> /tmp/test_crontab_env.file
手动执行, 运行结果:
2016-03-08 11:31:07 test_crontab_env
添加到 crontab 中如下
*/10 * * * * /home/hadoop/test_crontab_env.sh
结果:
$> cat /tmp/test_crontab_env.file
2016-03-08 11:31:07 11:36:01
2016-03-08 11:31:07 11:46:01
...
这里引用的环境变量无效了.

2.解决方案

在要执行的shell脚本开始执行时加载环境变量文件
#!/bin/bash
source /etc/profile
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  crontab command not found