LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-28-2009, 11:13 AM   #1
mek1
LQ Newbie
 
Registered: Aug 2008
Posts: 11

Rep: Reputation: 0
Question piping text to email


Hello,

Just started bash scripting. I'm managed to grep a logfile for system's date and export the results. The issue I am hung up on is a way to pipe the contents to the body of an email.

Here's what I thought would work;
Code:
cat /home/user1/ipReport.txt | mail -s "$hostname" user@domain.com
However I get an email without anything in it. I started trying 'tail' but that wont work either for obvious reasons to me now.

Can someone explain the best method of mailing text?

...woops I probably should have created this in 'Newbie'

Last edited by mek1; 04-28-2009 at 11:14 AM. Reason: wrong sub-forum
 
Old 04-28-2009, 11:34 AM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by mek1 View Post
Hello,

Just started bash scripting. I'm managed to grep a logfile for system's date and export the results. The issue I am hung up on is a way to pipe the contents to the body of an email.

Here's what I thought would work;
Code:
cat /home/user1/ipReport.txt | mail -s "$hostname" user@domain.com
However I get an email without anything in it. I started trying 'tail' but that wont work either for obvious reasons to me now.

Can someone explain the best method of mailing text?

...woops I probably should have created this in 'Newbie'
cat /path/to/file.txt | /usr/sbin/sendmail -t emailtogoto@domain.tld
or
cat /path/to/file.txt | /usr/sbin/sendmail -f fromaddr@domain.tld -F "Persons Name" toaddr@domain.tld

file.txt should look something like... (you can skip first line if you specify them on cmd line, and realistically even the To line, but it generally gives a better end result if you include them.)

Code:
From: "Persons Name" <fromaddr@domain.tld>
To: "To Addr" <toaddr@domain.tld>
Subject: Hello To!

Hi To,
  How's life been treating you, get in touch.

Persons
You can use mail or a variety of other tools to send it out, I just used sendmail as an example, but you need to know what the tool you're using expects and provide it.

Last edited by rweaver; 04-28-2009 at 11:39 AM.
 
Old 04-28-2009, 02:24 PM   #3
mek1
LQ Newbie
 
Registered: Aug 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks! That worked perfectly.
 
  


Reply


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
Email Piping w/o CPanel? guest Linux - Server 1 03-31-2009 06:41 PM
Help Piping a Text File Into rm chantrek Linux - Newbie 12 04-02-2007 08:44 AM
Piping output to text files corbis_demon Linux - General 3 10-12-2004 03:33 AM
Piping email to two destinations? tubedogg Linux - Newbie 2 12-04-2003 08:21 PM
Piping output to a text file joadoor Linux - Newbie 7 04-19-2002 03:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:49 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration