<Mail> attachment param is not working under system function

Hi Guys,

I have executed the mail command that has attachment with filename as current date enclosed in system function that is added under awk command.
I have used awk command to check if the error code is present in the file then email command sends an email with subject Error Code ,body provided in the file 'mailmessage.txt' and attachment of current date file .

awk '{if ($1 ~ /BIP8071I/)  {
DATE="`date '+%d%m%Y'`"
system("mail -s" $1 "test\\ "Information"\ emailid -a /home/test/abc_$DATE.txt <  /home/test/mailmessage.txt")
}

This command has executed without any flaws. But when I received the email, I didn't find the attachment . Instead, the -a parameter is coming in to section of the email box as provided in the attachment.

Can anyone suggest if this can be possible in system function.

Thanks.

Welcome to the forum.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS, shell, and, here, mail version. Some mail command just don't provide the -a attachment option.

BTW, your awk script has syntax errors, so I'd be surprised if it "has executed without any flaws". The DATE variable won't be assigned as the date command won't be executed.

Yes. You are right. When I tried to pass this file context as a body to the mail command before. I was getting error as file is not found like this :
FlowStats_.txt: No such file or directory

As well as even though, i have executed it as single line command as below :

DATE="`date '+%d%m%Y'`" mail -s"test" emailid -a /home/test/abc_$DATE.txt <  /home/test/mailmessage.txt

This was also not working.

I have also tried without parameter -a in the mail command. This is also not working.

Can you please provide the mail command that has attachment under system function.

Thanks.

------ Post updated at 01:51 PM ------

Hi Guys,

I can now able to send the attachment of current date file with the below command :

awk '{if ($1 ~ /BIP8071I/)  {
 
system("cat /home/test/mailmessage.txt|mail -s" $1 "test\\ "Information"\ -a /home/test/FlowStats_`date '+%d%m%Y'`.txt  emailid");
}'

Thanks.

------ Post updated at 01:53 PM ------

I hope this helps .