Sample Header Ad - 728x90

mailx command in Linux

0 votes
1 answer
374 views
The below code is working fine in a Unix server for sending mail along with attachments from an array variable, i.e DISCARDED_FILE_NAME, but the same code is not working in Linux server, since -m in mail command is not supported in Linux; instead of it we need to use -a. I have tried with it as shown below, but it is still not working. This code is working fine in a Unix server without any issue:
=$1
set -A DISCARDED_FILES $2
DISCARDED_FILE_NAME="DISCARDED"
echo "MRP_NAME" ${MRP_NAME}
RECEIVER="xyz@gmail.com"
echo "RECEIVER" ${RECEIVER}
SUBJECT="Error on ${MRP_NAME}"
BODY="Errore nell' elaborazione dell' ${MRP_NAME} Controllare file ${DISCARDED_FILE_NAME}"
echo "${BODY}"
(echo "$BODY\n";
for file in ${DISCARDED_FILES[@]}
do
uuencode $file echo $file | cut -d'/' -f9
done ) | mailx -m -s "${SUBJECT}" ${RECEIVER} 
echo mail sent
I modified accordingly to work in a Linux server but failed as shown below : This code is not working in a Linux server:
MRP_NAME=$1
set -A DISCARDED_FILES $2
DISCARDED_FILE_NAME="DISCARDED"
echo "MRP_NAME" ${MRP_NAME}
RECEIVER="xyz@gmail.com"
echo "RECEIVER" ${RECEIVER}
SUBJECT="Error on ${MRP_NAME}"
BODY="Errore nell' elaborazione dell' ${MRP_NAME} Controllare file ${DISCARDED_FILE_NAME}"
echo "${BODY}"
(echo "$BODY\n";
for file in ${DISCARDED_FILES[@]}
do
uuencode $file echo $file | cut -d'/' -f9
DISCARDED_FILES+=( "-a"  $file)  
done ) | mailx "${DISCARDED_FILES[@]}" -s "${SUBJECT}" ${RECEIVER} 
echo mail sent
When I ran the above code in Linux server I got the below text in mail (body) without any attachments.
Errore nell' elaborazione dell'  Controllare file DISCARDED\n
begin 660 shell.txt
3=F%R=6X@:70@:7,@:6X@8F]D>0
end
begin 660 MoneticalBatchExtlogs.txt
M9&-T97)I;#`Q.B]A'0O;&]G+T)312,@
M'0@35)0,#$@](#(Q.#X"ELQ-3HP-SHQ-UT@16YD
M(&=E;F5R871I;F<@N+BX*6S$U.CW
M.C$W72!3=&%R="!I;G-E
Asked by Naga Sai Varun (1 rep)
Sep 20, 2020, 12:47 PM
Last activity: Jan 31, 2024, 07:51 AM