运行HiveQL查询的Shell脚本



我是Unix Shell脚本世界的新手。我想从unix shell脚本运行一个简单的sql查询,并将结果输出到一个.txt文件中,然后将该.txt文件作为附件发送到电子邮件中。

SQL查询并将输出管道传输到txt文件:

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

我如何从shell脚本中做到这一点,并将输出发送到一个txt文件,然后将该txt文件作为附件发送到电子邮件中。

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

您可以在此处找到更多信息:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli

之后,你应该可以使用mutt在任何你喜欢的地方发送带有附件的电子邮件。请注意,您需要创建一些漂亮的preformated_mail.txt文件,它看起来像您想要的那样

#!/bin/bash
hive -e 'SELECT count(*) from pds_table' > attachment.tmp
mutt -s "Daily logs" -a attachment.tmp some@email.you.like < preformatted_mail.txt

最新更新