I am trying to send a mail with both a body and attachment to a specific mail, it is working fine on the command line.
However, when trying to run as part of a bash script it sends to mails that I have not even included and the subject is completely different as indicated and the attachment is also not present.
Tried to replicate this Bash script sending an e-mail with attachment, body and subject but not working as expected either.
Bash Script
#!/bin/bas
DATA_DIR=/Data
RUN_DIR=`basename "$DATA_DIR"`
REPORT_DIR=$DATA_DIR/Data/Reports
EXPERIMENT=$(awk -F',' '$1 == "Experiment " { print $2 }' $DATA_DIR)
COMPRESSED_DIR=$(tar -zcvf $REPORT_DIR.zip $REPORT_DIR)
#Mail Variables
SUBJECT="${EXPERIMENT} Report"
RECIPIENTS=user@domain.com
#Mail Body
cat > $PWD/message.txt << EOF
Experiment Name: ${EXPERIMENT}
Please find attached the associated reports
EOF
cat $PWD/body-message.txt | mail -s $SUBJECT -a $COMPRESSED_DIR $RECIPIENTS
echo "Mail Sent"
It does send the body and to the first e-mail I assign it. It then takes the arguments included in the body message as default mails. Not sure what is happening.
Thanks