1

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?

  • 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. – Tamara 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
0

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
| improve this answer | |
  • Go with script as @Hennes suggested above. A much more cleaner idea – Sudipta Chatterjee Jan 16 '13 at 7:21
0

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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