[英]Shell script to run HiveQL queries
I am new to Unix Shell Scripting world. 我是Unix Shell脚本世界的新手。 I wanted to run a simple sql 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.
我想从unix shell脚本运行一个简单的sql查询,并将结果输出到.txt文件中,然后将该.txt文件作为附件发送到电子邮件中。
SQL Query and piping the output to a txt file: SQL查询并将输出通过管道传递到txt文件:
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. 如何从Shell脚本执行此操作,然后将输出发送到txt文件,然后将该txt文件作为附件发送到电子邮件中。
hive -e 'SELECT count(*) from pds_table' > a.txt
You can find more information here: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli 您可以在这里找到更多信息: https : //cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli
After that you should be able to send an email with your attachment wherever you like using mutt. 之后,您应该可以在任何喜欢使用mutt的地方发送带有附件的电子邮件。 Note that you need to create some nice preformatted_mail.txt file which looks like the way you want it.
请注意,您需要创建一些漂亮的preformatted_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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.