Unable to attach a .txt file or .log file to mail and mailx command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to attach a .txt file or .log file to mail and mailx command
# 1  
Old 04-14-2017
Unable to attach a .txt file or .log file to mail and mailx command

Hi,
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 and i am not supposed to install it. I have tried many ways by googling which has not 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.

Code:
nohup Check.ksh > Valid_Check.log 2>&1 &

In Check.ksh

Code:
typeset var TO="name@domain.com";
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
Code:
#mailx -s "${SUB}" "${TO}" "${BODY}" < ${FILE_PATH}/Valid_Check.log

Code:
#cat ${FILE_PATH}/Valid_Check.log | mailx -s "${SUBJECT}" "${TO}" "${BODY}";

Code:
uuencode Valid_Check.log Valid_Check.log | mail -s "${SUB}" "${BODY}" ${TO}

But getting an error like "Valid... User unknown"
Any inputs would be helpful or any other simple/easy approach?

Thanks,
# 2  
Old 04-14-2017
Try mailx:

Code:
uuencode Valid_Check.log Valid_Check.log | mailx -s "${SUB} ${BODY}" ${TO}

Note the change in quotes.
# 3  
Old 04-14-2017
Smilie Thanks Jim, Its working now!
# 4  
Old 04-27-2017
Hi Jim,

Code:
mailx

command was working fine a week ago but i am not getting any email now in my inbox.

Any idea!? what could be the reason? As i don't see any error in log file.

Thanks.
# 5  
Old 04-27-2017
Look in your syslog file - for example the sendmail daemon may not be running.

If you cannot see that sendmail processed the mail request, try restarting.
# 6  
Old 04-27-2017
Thanks for the quick reply Jim. daemon is not running.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mailx command - Temporary mail file: permission denied

Hi , I am facing a problem with respect to mailx command in unix . Earlier it was working fine and I am facing this issue only from last week . I used mailx command and I am getting a error message as follows : temporary mail file: Permission denied If I run mailx command from... (2 Replies)
Discussion started by: deepav1985
2 Replies

2. Shell Programming and Scripting

How to attach multiple file to send mail command

Hi, i want color effect on mail as well as multiple attachment.I have code but this code is used for single attachment. I am unable to attach more than one file.:wall: I want to send two attachments -ahmed.csv and ahmed1.csv . Sample content: <html> <body> <b> Hi...</b> </body> </html> ... (1 Reply)
Discussion started by: AhmedLakadkutta
1 Replies

3. Shell Programming and Scripting

Attach file in mailx command

Hi I want ot send a mail with aatach a file for this i have tried mailx -s "COMPLETED: deal.sh" -a root/usr/local/bin/sched/nightly_Cronjob/test.out me@nowhere uuencode /usr/local/bin/sched/nightly_Cronjob/test.out /usr/local/bin/sched/nightly_Cronjob/test.out | mailx -s "COMPLETED:... (2 Replies)
Discussion started by: Himanshu_soni
2 Replies

4. Shell Programming and Scripting

Attach file in mailx command

Hi I want ot send a mail with aatach a file for this i have tried mailx -s "COMPLETED: deal.sh" -a /usr/local/bin/test.out me@nowhere uuencode /usr/local/bin/test.out /usr/local/bin/test.out | mailx -s "COMPLETED: deal.sh" me@nowhere but of command is not working. so is there any... (0 Replies)
Discussion started by: Himanshu_soni
0 Replies

5. UNIX for Dummies Questions & Answers

Unable to send e-mail using mailx command

Hi All, Can you please help me in solving this. I am facing some problem sending mails. If I use like this, I am able to send mail the mail echo "This is an automated e-mail; please do not reply." | mailx -s "Good Morning ." 'abc@xys.com' But if I use like this, then I am unable to send... (1 Reply)
Discussion started by: manas6
1 Replies

6. Shell Programming and Scripting

How to attach a file in Linux mail command

How to attach a file in Linux mail command Hi Guys, Is there any way to attach a file in Linux mail command without using "uuencode"? i.e. Code: file=/a/b/c/d/file.txtmail -s "Giga aks" abc@123.com <<HDoc`uuencode $file $file 2>/dev/null`HDoc Here, I don;t want to use 'uuencode'... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

7. UNIX for Advanced & Expert Users

unable to sent mail in html format by mailx command.

I use maix command to sent mails. i can sent only plain text mails. Unable to sent mails in html format. while sending mails in html format, the received mail has the html code only. (17 Replies)
Discussion started by: p_prathaban
17 Replies

8. Shell Programming and Scripting

Need to attach a txt file while sending mail

Hi, I need to attach a txt file while sending mail thru Unix. Please help me out in this.. -Charan. (9 Replies)
Discussion started by: charan81
9 Replies

9. UNIX for Dummies Questions & Answers

using mailx to send a log file to my outlook e-mail account

I like to use mailx -s to send an entire xxxxx.log to my outlook e-mail account. Any help will be appreciated. Thanks. (6 Replies)
Discussion started by: simt
6 Replies

10. UNIX for Dummies Questions & Answers

How to attach a file in mail?

Hi, I want to know how to send a mail in unix using mailx or mail or sendmail to send a mail with a file attached. I have read the answers from the other threads but I still don't understand. I want to do it in the command line as well as in script. Can anyone help? DO I need to use... (1 Reply)
Discussion started by: firebirdonfire
1 Replies
Login or Register to Ask a Question