LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Send attachment with mail from command line (http://www.linuxquestions.org/questions/linux-newbie-8/send-attachment-with-mail-from-command-line-4175432528/)

shivaa 10-16-2012 10:41 AM

Send attachment with mail from command line
 
Let's say one of my script is checking ping status on various servers, and then generates a text file containing the output from all the servers. So I want that my script itself send a mail to me (jack@somehost.com) with this text file as attachment. How can I achieve this? How to send an attachment from CLI? and which mail command should I use i.e. mail or mails or sendmail or mailx...
Thanks for any suggestions!

arun5002 10-16-2012 10:56 AM

Quote:

How to send an attachment from CLI?
To send Mail with attachment

Quote:

#mail -s "Subject" "mailid" < /var/log/mail.log

shivaa 10-16-2012 11:22 AM

Arun, are you sure that #mail -s "Subject" "mailid" < /var/log/mail.log will send mail.log file as an attachment?
As far as I am concerned, it will send this mail with /var/log/mail.log as mail body (i.e as text of mail body), NOT as an attachment.

xhack 10-16-2012 11:45 AM

You're correct. That method would send it as the body of the message. If you have mutt installed though, you can use something like the command below to do this.

mutt -s "Subject" -a /var/log/mail.log some@address.com

arun5002 10-16-2012 11:53 AM

These link tells you how to send Email with attachment

http://www.cyberciti.biz/tips/sendin...ttachment.html

shivaa 10-17-2012 12:18 AM

Quote:

Originally Posted by xhack (Post 4807353)
You're correct. That method would send it as the body of the message. If you have mutt installed though, you can use something like the command below to do this.

mutt -s "Subject" -a /var/log/mail.log some@address.com

Friends, you're right that I can use mutt or I can follow any stuff available on internet. But I have to invoke my script on a live production server, which has Solaris 10 and my limitation is that I cannot do any such software installation like mutt on such live servers, just for sake of sending an attachment. I am sorry, but is there any simple way? or any other commands available on Solaris 10..?

chrism01 10-17-2012 12:23 AM

http://www.cyberciti.biz/faq/howto-u...l-attachments/

xhack 10-17-2012 12:26 PM

Quote:

Originally Posted by meninvenus (Post 4807819)
Friends, you're right that I can use mutt or I can follow any stuff available on internet. But I have to invoke my script on a live production server, which has Solaris 10 and my limitation is that I cannot do any such software installation like mutt on such live servers, just for sake of sending an attachment. I am sorry, but is there any simple way? or any other commands available on Solaris 10..?


Ahh. It would've been quite helpful to know your OS as well as package limitations, to better recommend something to you. In this case chrism01 has already posted the link that should get you on track

shivaa 12-07-2012 11:42 AM

Command that worked file (Solaris 10):
Code:

uuncode </file/to/attach> </file/to/attach> | mailx -s "<subject>" <list_of_reciepents>


All times are GMT -5. The time now is 03:30 PM.