简体   繁体   English

使用mailx在电子邮件中发送多个文件作为附件

[英]sending multiple files as attachment in e-mail using mailx

I have a requiremnet to send multiple files as e-mail attachmnet in shell script. 我有一个requiremnet以外壳程序脚本的形式发送多个文件作为电子邮件attachmnet。 I have used below command. 我用下面的命令。

(printf "%s\n" "BODY"; uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt ) | mailx -m -s "TEST" emailid@domain.com

However the number of files i want to send as an attachmnet are dynamic. 但是,我要作为Attachmnet发送的文件数是动态的。 So I want to assign the uuencode ... comand to a variable and then use it. 所以我想将uuencode ... comand分配给一个变量,然后使用它。 I have tried below way, 我已经尝试过以下方式,

$ ATTACH_CMD=$(echo `cat $OUTPUT_FILE`)
$ echo $ATTACH_CMD
uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt

$ (printf "%s\n" "BODY"; $ATTACH_CMD ) | mailx -m -s "TEST" emailid@domain.com

And i am getting below error. 而且我正在错误以下。

sh: uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt:  not found.

Can any one please help me with this? 有人可以帮我吗? Thanks in advance. 提前致谢。

Have you tried using the below code? 您是否尝试过使用以下代码? Not sure why it works, but maybe the below code could be used as a workaround 不知道为什么它起作用,但是下面的代码可以用作解决方法

(printf "%s\n" "BODY"; `echo $ATTACH_CMD` ) | mailx -m -s "TEST" emailid@domain.com`?

For $ATTACH_CMD I have used echo command. 对于$ATTACH_CMD我使用了echo命令。

I finally found the way. 我终于找到了路。 eval makes the trick 评估使窍门

eval $STR 

$ ATTACH_CMD=$(echo `cat $OUTPUT_FILE`)
$ echo $ATTACH_CMD
uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt

$ (printf "%s\n" "BODY"; eval $ATTACH_CMD ) | mailx -m -s "TEST" emailid@domain.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM