To schedule a hive query on Crontab

为君一笑 提交于 2020-04-30 08:40:09

问题


Can any one help me to schedule a job in Crontab which will execute a simple Hive query on specific time and provide me the output in text/log file.

I have created a batch script to execute a select query , but getting error("Hive command not found") while executing it in Crontab. However same script is running fine through shell. Below is my script :

ip.sh
#!/bin/bash
echo "Starting of Job"
cd /home/hadoop/work/hive/bin
hive -e 'select * from mytest.empl'
echo "Script ends here"

Crontab: 10 * * * * /home/hadoop/work/ip.sh >> /home/hadoop/work/quryout.log 2>&1

After executing the Crontab , I am getting below message in log:

Output(Queryout.log): Starting Of Job hive command not found in ip.sh at line number 4 Script ends here


回答1:


Add these lines in your /home/hadoop/.bashrc:

export HIVE_HOME=/home/hadoop/work/hive
export PATH=$PATH:$HIVE_HOME/bin

Now, change your script like this:

#!/bin/bash
echo "Starting of Job"
hive -e 'select * from mytest.empl'
echo "Script ends here"



回答2:


try this in shell script

/home/hadoop/work/hive/bin/hive -e 'select * from mytest.empl'


来源:https://stackoverflow.com/questions/30521650/to-schedule-a-hive-query-on-crontab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!