I am trying to attach a .log file or .txt file to mail command to send an email once my ksh script executed. I am unable to use mutt command as it has been not installed in my machine and i am not supposed to install it. I have tried many ways by googling which has not been helped me to succeed.
Here is my requirement,I need to run some 10 sql queries and result need to send in the email via attachment. I have Check.ksh
and i am running this by using nohup
command.
nohup Check.ksh > Valid_Check.log 2>&1 &
In Check.ksh
typeset var TO="[email protected]";
typeset var SUB="Report";
typeset var BODY="Check Completed";
typeset var ATTACHMENT=${FILE_PATH}/Valid_Check.log
if [ -f "${ATTACHMENT}" ]; then
echo "Log file exist";
else
echo "No Log File";
fi
uuencode Valid_Check.log Valid_Check.log | mail -s "${SUB}" "${BODY}" ${TO}
and tried the below as well
#mailx -s "${SUB}" "${TO}" "${BODY}" < ${FILE_PATH}/Valid_Check.log
#cat ${FILE_PATH}/Valid_Check.log | mailx -s "${SUBJECT}" "${TO}" "${BODY}";
Above code throwing an error like "Valid... User unknown"
Any inputs would be helpful or any other simple/easy approach?
Thanks,
Valid
somehow ends up in$TO
but the code you posted does not produce this result.uuencode
should definitely be your last resort. If yourmailx
supports attachments, definitely use this facility instead. MIME has been widely supported for over 20 years now.$BODY
with uuencoded standard input might not be supported by yourmail
ormailx
commands, but these are poorly standardized and have different capabilities on different platforms and of course also between versions. What platform are you on and what versions of there software packages are you using?mail -s "${SUB}" ${TO} <<< ${BODY}
then it is sending an email but with attachment not sure why it is not working.uuencode
format. As a deperate fallback, append the uuencode data to the body with an empty line in between.