Grokbase Groups Hive user July 2012
FAQ

[Hive-user] Run simple HiveQL query using shell script?

Raihan Jamal
Jul 18, 2012 at 5:29 am
I am new to Unix Shell Scripting world. I wanted to run a simple
*HiveQL*query from the Unix Shell script and output the result in a
.txt file and
then send that .txt file as an attachment in an email.

SQL Query and piping the output to a txt file is below:

SELECT count(*) from pds_table > a.txt;

How can I do this from a shell script and send the output to a txt file and
then send that txt file as an attachment in an email.


*Raihan Jamal*
reply

Search Discussions

3 responses

  • Vinod Singh at Jul 18, 2012 at 6:31 am
    hive -e "SELECT count(*) from pds_table" > a.txt

    Thanks,
    Vinod
    On Wed, Jul 18, 2012 at 10:58 AM, Raihan Jamal wrote:

    I am new to Unix Shell Scripting world. I wanted to run a simple *HiveQL*query from the Unix Shell script and output the result in a .txt file and
    then send that .txt file as an attachment in an email.

    SQL Query and piping the output to a txt file is below:

    SELECT count(*) from pds_table > a.txt;

    How can I do this from a shell script and send the output to a txt file
    and then send that txt file as an attachment in an email.


    *Raihan Jamal*
  • Raihan Jamal at Jul 18, 2012 at 6:34 am
    I know by that way I can pipe the output to some txt file, but is there any
    way I can do within some sort of shell script so that If I need to schedule
    that shell script to run daily at some particular time, then it should work
    that way also and also I need to send that txt file as an attachment in an
    email.




    *Raihan Jamal*


    On Tue, Jul 17, 2012 at 11:30 PM, Vinod Singh wrote:

    hive -e "SELECT count(*) from pds_table" > a.txt

    Thanks,
    Vinod

    On Wed, Jul 18, 2012 at 10:58 AM, Raihan Jamal wrote:

    I am new to Unix Shell Scripting world. I wanted to run a simple *HiveQL*query from the Unix Shell script and output the result in a .txt file and
    then send that .txt file as an attachment in an email.

    SQL Query and piping the output to a txt file is below:

    SELECT count(*) from pds_table > a.txt;

    How can I do this from a shell script and send the output to a txt file
    and then send that txt file as an attachment in an email.


    *Raihan Jamal*
  • Vinod Singh at Jul 18, 2012 at 6:41 am
    That is what I meant. Hive CLI can be invoked from a shell script. And
    query can be changed to something like-

    "INSERT OVERWRITE LOCAL DIRECTORY <PATH_TO_DIR> SELECT count(*) from
    pds_table"

    Thanks,
    Vinod
    On Wed, Jul 18, 2012 at 12:04 PM, Raihan Jamal wrote:

    I know by that way I can pipe the output to some txt file, but is there
    any way I can do within some sort of shell script so that If I need to
    schedule that shell script to run daily at some particular time, then it
    should work that way also and also I need to send that txt file as an
    attachment in an email.




    *Raihan Jamal*


    On Tue, Jul 17, 2012 at 11:30 PM, Vinod Singh wrote:

    hive -e "SELECT count(*) from pds_table" > a.txt

    Thanks,
    Vinod

    On Wed, Jul 18, 2012 at 10:58 AM, Raihan Jamal wrote:

    I am new to Unix Shell Scripting world. I wanted to run a simple *HiveQL
    * query from the Unix Shell script and output the result in a .txt file
    and then send that .txt file as an attachment in an email.

    SQL Query and piping the output to a txt file is below:

    SELECT count(*) from pds_table > a.txt;

    How can I do this from a shell script and send the output to a txt file
    and then send that txt file as an attachment in an email.


    *Raihan Jamal*

Related Discussions

Discussion Navigation
viewthread | post

2 users in discussion

Vinod Singh: 2 posts Raihan Jamal: 2 posts