bash 如何在mailx命令中抄送邮件列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12419255/
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
How to cc a maillist in mailx command
提问by arun KUMAR
I had prepared a cc maillist as below:
我准备了一个抄送邮件列表如下:
/appl/tracker/TEST> more abc.maillist
[email protected], [email protected], [email protected]
And a to maillist as below:
和一个邮件列表如下:
/appl/tracker/TEST> more Servicedesk.maillist
[email protected]
My script is ab.sh
which will call the mailx
command and send an email. This should send email to cc_list
keeping the id's in cc and to_list
placing the id provided in the list in to list.
我的脚本ab.sh
将调用mailx
命令并发送电子邮件。这应该发送电子邮件以cc_list
将 ID 保存在 cc 中,to_list
并将列表中提供的 ID 放入列表中。
/appl/tracker/TEST> more ab.sh
#!/bin/ksh
l_date=`date +%d%m%y`
CC_LIST=`cat /appl/tracker/TEST/abc.maillist`
TO_LIST=`cat /appl/tracker/TEST/Servicedesk.maillist`
MY_Q="'"
cc_list="$MY_Q$CC_LIST$MY_Q"
echo $cc_list
BODYFILE='Please find attached file having my details.Test mail'
echo $CC_LIST
echo $TO_LIST
mailx -s 'HI' -c $cc_list $TO_LIST <<-EOF
`echo $BODYFILE`
EOF
/appl/tracker/TEST>
Output:
输出:
There is an error being occured stating that there is an unbalanced "
.
Can anyone please help me getting the solution for this.
发生错误,说明存在不平衡"
. 任何人都可以帮我解决这个问题。
回答by tripleee
I don't get that error message. Are you sure you have pasted everything correctly?
Anyway, an immediate problem is that you need to quote any variable interpolations. It's not clear why you need variables for this at all, besides. Here is a much simplified refactoring of your script.
我没有收到那个错误信息。您确定您已正确粘贴所有内容吗?
无论如何,一个直接的问题是您需要引用任何变量插值。此外,尚不清楚为什么您需要变量。这是对脚本的简化得多的重构。
#!/bin/sh
CC_LIST=`cat /appl/tracker/TEST/abc.maillist`
TO_LIST=`cat /appl/tracker/TEST/Servicedesk.maillist`
BODYFILE='Please find attached file having my details. Test mail'
echo "$CC_LIST"
echo "$TO_LIST"
echo "$BODYFILE" | mailx -s 'HI' -c "$CC_LIST" "$TO_LIST"
回答by Nahuel Fouilleul
Variables must be double quoted to avoid expanding as list:
变量必须双引号以避免扩展为列表:
mailx -s 'HI' -c "$cc_list" "$TO_LIST" <<-EOF
$BODYFILE
EOF