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
一个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
相关文章推荐
- Pull is not possible because you have unmerged ...
- CentOS下使用yum命令安装计划任务程序crontab
- Ubuntu 下修改 Could not reliably determine the serve
- Linux任务前后台的切换
- 解决Default storage engine (InnoDB) is not available导致mysql无法启动的修改办法
- MySQL4 File ‘c:\mysql\share\charsets\?.conf’ not found (Errcode: 22)的解决方法
- asp中command的在单条记录时,有些字段显示为空的问题
- Delphi Command模式
- SQL中IS NOT NULL与!=NULL的区别
- 解析Ubuntu下crontab命令的用法
- mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
- movie not found的解决办法(iis)
- linux crontab实例分析
- 关于crontab的使用详解
- php设计模式 Command(命令模式)
- 解决bash: mysql: command not found 的方法
- 记一次LINUX-CRONTAB失败的排查案例
- 执行setup,报错 -bash: setup: command not found
- bash:.....:command not found
- 好RESTful API的设计原则