How to cc a maillist in mailx command
24,882
Solution 1
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"
Solution 2
Variables must be double quoted to avoid expanding as list:
mailx -s 'HI' -c "$cc_list" "$TO_LIST" <<-EOF
$BODYFILE
EOF
Author by
arun KUMAR
Updated on September 16, 2020Comments
-
arun KUMAR almost 4 years
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 themailx
command and send an email. This should send email tocc_list
keeping the id's in cc andto_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.-
tripleee almost 12 yearsThe echo in backticks in a here document is a horribly complex and convoluted way of passing a variable to a script.
-