email - cron: sending output to file then EMAILing file to me -


I am writing a series of cron jobs that I want to log my work to the file in my output And then I should say the contents of the file - when I say @ somewhere.com

I think the file can be done using simple pipes to output redirection like this: < / P>

  30 0 * * * / path / to / script1 & gt; Task1.log 30 1 * * * / path / to / script2 & gt;   

However, I'm not sure how to mail files (or just their content) to me@somewhere.com in a separate email

Besides, there Depending on the date, there is a way to create a log file name dynamically, so that the log name is like some% Y% m% d.task1.log?

Where is the prefix date?

I am running on Ubuntu 10.0.4 LTS

If your system is a The job is not / usr / bin / sendmail ( sendmail sending , most mail servers provide a / usr / bin / Sendmail wrapper script), you can use mail (1) to send mail:

  echo "hello world" | Mail-hello me@example.com   

Mail (1) is very primitive; No MIME file is attached, you are stuck with plain text

If mutt (1) is installed, you can use MIME to attach files Are:

  "Hello World". Mutt -a work * .log - me@example.com   

To pass the logfile dates:

  $ echo "hi" & gt; $ (Date "+% Y% m% dlog.txt") $ cat 20110328log.txt Hi $   

So, try it:

  30 1 * * * / Path / to / script2 & gt; $ (Date "+ \% Y \% m \% dlog.txt") & amp; Amp; Mutt -a $ (date "+ \% Y \% m \% dlog.txt") - me@example.com    

Comments