LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-29-2005, 01:25 AM   #1
ioanv
LQ Newbie
 
Registered: Mar 2005
Location: Buc, Romania
Distribution: Red Hat 9
Posts: 10

Rep: Reputation: 0
Automated mail


I'm generating a few logs on my linux box which is also a mail server with qmail.
I would like to send this files to my yahoo mail account.
I can run the "mail user@yahoo.com" command in crontab however this doesn't solve my problem since mail is an interactive command. Is there some parameter that i can run with the mail command to automaticaly attach those files?

Tnx
 
Old 03-29-2005, 02:13 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Maybe the result of this solution is not to your liking, but mail is somewhat basic.

cat log | mail -s "Subject goes here" user@some.mail.box

You will end up with a mail that has the content of log, not as an attachment, but as readable text.

Hope this helps.
 
Old 03-29-2005, 02:25 AM   #3
ioanv
LQ Newbie
 
Registered: Mar 2005
Location: Buc, Romania
Distribution: Red Hat 9
Posts: 10

Original Poster
Rep: Reputation: 0
that was perfect, druuna, thank you very much

one more thing: is there a way to include in the subject the name of the file? in case that i have more than one type of logs and i need to tell them appart

maybe something like
cat log | mail -s "Subject goes here" & <file name> user@some.mail.box ?????
 
Old 03-29-2005, 02:35 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you put these lines in your crontab (one for every logfile), just type the name in the subject line

cat /var/log/messages | mail -s "Log: messages Date: `date`" user@some.mail.box

The above example puts the name of the file (you typed it) and the date (automated) in the subject line.

If you want to automate this for several logfiles, you need to write a (simple?) shell script.

Code:
#!/bin/bash
cd /var/log
for THIS_FILE in *log
do
  cat $THIS_FILE | mail -s "Log: ${THIS_FILE}" user@some.mail.box
done
This script can be run at a specific time/date from crontab.
As you probably can see, the above script is a rough example.

Hope this helps.
 
Old 03-29-2005, 02:47 AM   #5
ioanv
LQ Newbie
 
Registered: Mar 2005
Location: Buc, Romania
Distribution: Red Hat 9
Posts: 10

Original Poster
Rep: Reputation: 0
that's exactly what i wanted, druuna

now i understand how can i custom the mail according to my needs

thanks big time
 
  


Reply



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
Automated Backups Matir Linux - Software 2 06-28-2005 08:55 AM
automated NCFTPPUT innuendo_98 Programming 3 03-22-2005 01:42 PM
Automated E-Mail cleansing. Thrifty Linux - Software 0 02-20-2004 12:17 PM
Automated HW/SW inventory. welby Linux - Software 2 07-10-2003 07:28 AM
Automated su script? elmetald00d Linux - General 5 04-08-2002 11:17 PM

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

All times are GMT -5. The time now is 01:38 PM.

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