bash uuencode 无法正常使用我的以下命令附加文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11943467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uuencode doesn't work properly for attaching files with my below command
提问by arsenal
I am trying to attach one fileand send few echo messagesin the Body of an email using mailx and uuencode. I have below command which I have added them together, and uuencode doesn't work properly but I get echo message properly in my email.
我想attach one file和发送数echo messages的机身采用电子邮件的mailx and uuencode。我有以下命令,我已将它们添加在一起,并且 uuencode 无法正常工作,但我在电子邮件中正确收到了回显消息。
How can I make uuencode works here? Something wrong I am doing here I guess while combing uuencode with mailx?
我怎样才能让 uuencode 在这里工作?我猜在将 uuencode 与 mailx 结合时我在这里做错了什么?
(uuencode /tmp/chart.html percentage_graph.html) | mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r [email protected] [email protected] <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table
Total Items Purchased: `echo $QUERY1 | awk '{print }'`
Total Items MissingorMismatch: `echo $QUERY1 | awk '{print }'`
Error Percentage: $QUERY2
EOF
But for testing purpose if I issue below command to see whether I am getting any html file or not in an attachment, then I get an email with the attachment properly.
但是出于测试目的,如果我发出以下命令以查看我是否在附件中收到任何 html 文件,那么我会正确收到一封带有附件的电子邮件。
(uuencode /tmp/chart.html percentage_graph.html) | mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r [email protected] [email protected]
Then what's wrong in my first command when I combine them together?
那么当我将它们组合在一起时,我的第一个命令有什么问题?
回答by ghoti
The mailxcommand can get its input from the pipe (uuencode) or the heredoc (<< EOF). But not both.
该mailx命令可以从管道 (uuencode) 或 heredoc (<< EOF) 获取其输入。但不能两者兼而有之。
This may work for you:
这可能对您有用:
$ mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r [email protected] [email protected] <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table
Total Items Purchased: `echo $QUERY1 | awk '{print }'`
Total Items MissingorMismatch: `echo $QUERY1 | awk '{print }'`
Error Percentage: $QUERY2
$(uuencode /tmp/chart.html percentage_graph.html)
EOF
Alternately, consider using something like muttwhich will let you attach files separately from the body of the message.
或者,考虑使用诸如mutt 之类的东西,它可以让您将文件与邮件正文分开附加。
回答by Chris Dodd
uuencode doesn't read stdin if you give it an input filename as you have done here. That's because it encodes a single file. if you want to encode two files, you need to combine them together somehow first. You could just use catif concantenating them is ok:
如果您像此处所做的那样为其提供输入文件名,则 uuencode 不会读取标准输入。那是因为它对单个文件进行编码。如果要对两个文件进行编码,则需要先以某种方式将它们组合在一起。cat如果连接它们没问题,您可以使用:
cat /tmp/chart.html - | uuencode percentage_graph.html | mailx .... << EOF
..stuff to append to chart.html
EOF

