Linux – Capturing the console output

bashconsolelinuxshell

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?

Best Answer

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
Related Question