LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-16-2012, 10:41 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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!
 
Old 10-16-2012, 10:56 AM   #2
arun5002
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 549
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
How to send an attachment from CLI?
To send Mail with attachment

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

Last edited by arun5002; 10-16-2012 at 10:58 AM.
 
Old 10-16-2012, 11:22 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
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.

Last edited by shivaa; 10-16-2012 at 11:25 AM.
 
Old 10-16-2012, 11:45 AM   #4
xhack
LQ Newbie
 
Registered: Jun 2011
Distribution: AntiX
Posts: 19

Rep: Reputation: 12
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
 
Old 10-16-2012, 11:53 AM   #5
arun5002
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 549
Blog Entries: 5

Rep: Reputation: Disabled
These link tells you how to send Email with attachment

http://www.cyberciti.biz/tips/sendin...ttachment.html
 
Old 10-17-2012, 12:18 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
Originally Posted by xhack View Post
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..?

Last edited by shivaa; 10-17-2012 at 12:37 AM.
 
Old 10-17-2012, 12:23 AM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
http://www.cyberciti.biz/faq/howto-u...l-attachments/
 
Old 10-17-2012, 12:26 PM   #8
xhack
LQ Newbie
 
Registered: Jun 2011
Distribution: AntiX
Posts: 19

Rep: Reputation: 12
Quote:
Originally Posted by meninvenus View Post
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
 
Old 12-07-2012, 11:42 AM   #9
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Command that worked file (Solaris 10):
Code:
uuncode </file/to/attach> </file/to/attach> | mailx -s "<subject>" <list_of_reciepents>
 
  


Reply

Tags
attachment, command line, mail, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send an e-mail with the command line? professorgenival Linux - Server 4 09-13-2010 02:05 AM
Debian etch - Unable to send mail from command line or from php mail command lqforumuser Linux - Newbie 1 03-01-2009 06:56 AM
command line email client to send mail to remote mail server dhanju Linux - Software 1 03-07-2008 06:37 AM
How to send mail from command line buskmann Linux - Newbie 7 07-23-2006 10:18 PM
Command Line Send Mail nutthick Linux - Newbie 10 01-24-2005 07:52 PM


All times are GMT -5. The time now is 07:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration