Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 运行HiveQL查询的Shell脚本_Sql_Bash_Shell_Unix_Hive - Fatal编程技术网

Sql 运行HiveQL查询的Shell脚本

Sql 运行HiveQL查询的Shell脚本,sql,bash,shell,unix,hive,Sql,Bash,Shell,Unix,Hive,我是Unix Shell脚本世界的新手。我想从unixshell脚本运行一个简单的sql查询,并将结果输出到一个.txt文件中,然后将该.txt文件作为附件发送到电子邮件中 SQL查询并将输出管道化为txt文件: SELECT count(*) from pds_table > a.txt; 如何从shell脚本执行此操作,并将输出发送到txt文件,然后将该txt文件作为电子邮件附件发送 hive -e 'SELECT count(*) from pds_table' > a.tx

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

SQL查询并将输出管道化为txt文件:

SELECT count(*) from pds_table > a.txt;
如何从shell脚本执行此操作,并将输出发送到txt文件,然后将该txt文件作为电子邮件附件发送

hive -e 'SELECT count(*) from pds_table' > a.txt
您可以在此处找到更多信息:

之后,你应该能够发送电子邮件与您的附件,无论你喜欢使用mutt。请注意,您需要创建一些很好的预格式化的_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
您可以在此处找到更多信息:

之后,你应该能够发送电子邮件与您的附件,无论你喜欢使用mutt。请注意,您需要创建一些很好的预格式化的_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

我知道我可以这样做。但是假设我需要每天运行相同的查询,并将a.txt文件作为附件发送到电子邮件中?那我该怎么做呢,这就是我想做的……对不起,我没有完全阅读你的问题;更新了使用mutt的建议。感谢Amestig的建议,但当我尝试这样做时,我得到了“mutt:not found”。除了mutt,还有其他发送电子邮件的方式吗?或者你想让我建议的其他方法?在构建或下载一个预构建的包时,它应该非常先进。如果你运行的是debian/ubuntu,那么你只需要做apt-get-install就可以了,我知道我可以用这种方式来做。但是假设我需要每天运行相同的查询,并将a.txt文件作为附件发送到电子邮件中?那我该怎么做呢,这就是我想做的……对不起,我没有完全阅读你的问题;更新了使用mutt的建议。感谢Amestig的建议,但当我尝试这样做时,我得到了“mutt:not found”。除了mutt,还有其他发送电子邮件的方式吗?或者你想让我建议的其他方法?在构建或下载一个预构建的包时,它应该非常先进。如果您运行的是debian/ubuntu,那么只需执行apt-get-install-mutt就可以了