用crontab设置hive脚本的自动执行及shell 127返回码的解决
测试用crontab设置一段hive ETL脚本的自动执行,期间遇到了一个问题
设置好的脚本01.sh在命令行模式下 ./01.sh 可以执行,但是配置到crontab中就返回127码,hive后的任何命令都不执行
查看了其他网友贡献的解决方案,终于搞定。
解释一下127码:127码代表未找到命令,0代表成功执行。
所以我这里返回127说明crontab在执行01.sh时找不到hive命令。这就很神奇了,我单独敲hive -f 02.hive 是可以执行的,echo $HIVE_HOME 也是能显示路径的。想不通,最后没办法了 只好在shell脚本中再次指定一下环境变量 . /etc/profile(注意.与/之间的空格)。这里有一个可能,有两个环境变量的配置文件 /etc/profile /etc/bashrc 我hive_home开始是配置在/etc/bashrc,其他的比如 JDK/HADOOP/HBASE等等都是配置在/etc/profile 。别问我为啥整两个地方。我也忘了为啥。后来我都放到/etc/profile里了。但并不好使,还是得配置. /etc/profile在shell文件里。话不多说,看代码。
crontab内容
*/1 * * * * /home/hadoop/apache-hive-2.3.4-bin/01.sh /dev/null 2>&1>
*/1 * * * * echo $(date) >> /home/hadoop/test.txt
01.sh内容
#!/bin/bash
. /etc/profile
echo hello >> /home/hadoop/test.txt
hive -f /home/hadoop/apache-hive-2.3.4-bin/02.hive
exitCode=$?
if [ $exitCode -ne 0 ];then
echo "hive execute failed,error_code:"$exitCode >> /home/hadoop/test.txt
exit $exitCode
fi
echo done >> /home/hadoop/test.txt
02.hive内容
use test;
drop table t1;
- shell脚本直接执行没有问题,crontab定时执行失败的解决方法
- Linux下shell脚本手动执行和放在crontab中自动执行的结果不一样
- crontab : 设置脚本自动执行命令
- [转] 关于crontab无法执行shell脚本的解决办法
- Linux crontab定时执行Shell脚本时的一个小坑:一种类似场景 (当需要执行特定的命令时) 解决思路
- Linux下shell脚本在crontab中一个周期执行不完,下周期任务被重复执行的问题解决
- shell脚本直接执行没有问题,crontab定时执行失败的解决方法
- Linux crontab定时执行Shell脚本需要执行特定的命令时解决思路
- shell脚本秒级自动执行之crontab完美应用
- shell脚本直接执行没有问题,crontab定时执行失败的解决方法
- 利用Crontab设置每个月第一个周六的17:30执行/opt/shell.sh 脚本
- linux crontab 无法执行shell脚本解决方法
- shell脚本直接执行没有问题,crontab定时执行失败的解决方法
- linux直接执行shell脚本正常,使用定时任务crontab执行出错
- centos 设置定时任务执行指定脚本与Crontab的格式
- 利用shell脚本执行ssh远程另一台主机执行命令并返回命令的结果集
- 【Linux】执行shell脚本出现异常:bad interpreter: No such file or directory如何解决
- 用shell脚本为ubuntu自动添加用户,并限定通过ssh连接该用户只能执行特定某个(或某几个)程序
- ubuntu 14.04遇到“已安装的 post-installation 脚本 返回了错误号 127 ”问题的解决
- 使用crontab,让linux定时执行shell脚本