Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am running a Hadoop hive query from shell script. This is how I am doing it in my shell script.

echo "SELECT COUNT(*) FROM test" | hive

I want to capture the output whatever hive command outputs. So, I am running my shell script as:

./hivequery.sh 2>&1 | tee output.txt

But, I am not able to capture the output of the hive command. How can I do that?

share|improve this question
    
Out of curiosity, why are you using tee? Does it work with simple redirection, ./hivequery.sh 2>&1 > output.txt? Does it work if you run the echo and hive commands directly from the terminal? –  terdon Jan 15 '13 at 11:50
    
Use |& instead of the old 2>&1 | syntax, it's shorter. Try without tee first, then read man tee and play around with the parameters to get it to do what you want. If tee doesn't work, you'll need to find an alternative. –  Tom Wijsman Jan 15 '13 at 11:51
    
Thanks. I checked with the redirection, but it didn't work. :-( –  divinedragon Jan 15 '13 at 12:12
1  
Did you try script? E.g. script elm will capture all output from the program elm, including colour codes and refreshes`. The copy of all output will be logged in a file. –  Hennes Jan 15 '13 at 13:38

2 Answers 2

up vote 0 down vote accepted

Got it. I added the redirection operator in the shell command itself inside the script.

echo "SELECT COUNT(*) FROM test" | hive 2>&1

The script too worked.

script -c ./myscript.sh output.txt
share|improve this answer
    
Go with script as @Hennes suggested above. A much more cleaner idea –  Sudipta Chatterjee Jan 16 '13 at 7:21

Try this:

$HIVE_HOME/bin/hive -S -e 'select a.col from tab1 a' > a.txt

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.