Problem with -c option in Mailx command

Hi,

I am using mailx command in shell script. When i put -c option for CC , i get error message as "Unknown flag: -c" . I checked manual of mailx command and found that ~c to be used but after using ~c also it is not working. My shell is Korn. Kindly let me know what i have to do .

Thanks

can you post the script, it is working fine for me.

Here is part of script where i am using mailx command

while read name ccname
do
  tr -d ' ' < report.txt > mod_report.txt
  uuencode mod_report.txt Monthly_report.txt > attachment.txt
  cat message.txt attachment.txt > combined.txt
  mailx -s "Monthly report" -c $ccname  $name < combined.txt
done < maillist.txt

maillist.txt contains mailid's

while read name ccname
> do
> mailx -s "test" -c $ccname $name <testing.txt
> done <mailid.txt

It worked fine for me at ksh prompt.

What is the error you are facing while you execute this script. Can you check for any empty lines in your maillist.txt file especially at the end.

i get error " Unknow flag : -c". Even when i execute at command prompt or through shell script it gives same error. I checked maillist.txt file no empty line.

user.m17878: mailx -s "test" -c abc@xyz.com
Unknown flag: -c

 # mailx -s "test" -c abc@xyz.com
The flags you gave are used only when sending mail.
Usage: mailx -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address
                -s SUBJECT -f FILE users

I get this error when my command is incomplete. Try to send mail manually from the prompt.

I tried sending mail from prompt then also it gives same error. "unknown flag -c".

I checked mail manaul and found ~c for CC but even then also i am facing problem.

mailx -s "test" ~c xyz@xyz.com then also it goes in To list for xyz@xyz.com and ~c@xyz.com

What Operating System and version are you using?

Some ideas about how to use "mailx with ~c" in one of my previous posts.
http://www.unix.com/shell-programming-scripting/140384-hpux-mailx-cc-list.html

If you search for "mailx cc" in this site there are loads more ideas but without knowing the format of your mail address list file it's hard to guess.

Tilde escapes need to be in the start of the message, not on the command line, e.g.

echo "~c $ccname" > combined.txt
cat message.txt attachment.txt >> combined.txt
mailx -s "Monthly report" $name < combined.txt

Thanks a lot Ygor.....Its working now :slight_smile: