Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

./ 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, ./ 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
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
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 ./ 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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .