简体   繁体   中英

How to cc a maillist in mailx command

I had prepared a cc maillist as below:

/appl/tracker/TEST> more abc.maillist
xyz@yahoo.com, a123@gmail.com, abc@xyz.com

And a to maillist as below:

/appl/tracker/TEST> more Servicedesk.maillist
123@gmail.com

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.

/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.

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"

Variables must be double quoted to avoid expanding as list:

mailx -s 'HI'  -c "$cc_list" "$TO_LIST" <<-EOF
$BODYFILE
EOF 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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