I want to send an email after cron job

I am using centos 6.4.
I have a few cron jobs setup and they all work fine.
However, I would like to enhance one of the crons.
This is what I have at the moment:

nice rsync -au /home/samba/wsaler/* /home/samba/wsaler.backup/wsaler.backup18pm

date | /bin/mail -s "wsaler 3:00pm backup finished" jc@ukzone.com

This works fine but I would like to improve on it like this:

nice rsync -au /home/samba/wsaler/* /home/samba/wsaler.backup/wsaler.backup18pm

date | /bin/mail -s "wsaler the curent date and time backup finished" jc@ukzone.com

Any suggestions will be appreciated.

Thanks,

John C

Wouldn't the mail's source text contain that time stamp?

grep "^Date:" mailfile
Date: Sat, 21 Feb 2015 12:24:09 -0600 (CST)

Hi RudiC...
Thanks for your reply.

Yes it would. However, the emails will be listed and I want to see the date in the SUBJECT line. i.e.

date | /bin/mail -s "wsaler the curent date and time backup finished" jc@ukzone.com

This shows in the email Subject:

I want it to read

I hope this makes it clearer what I am trying to achieve.

Thanks,

John C

Well understood. Still you could use grep on your mail file:

grep -E "^(From|Date|Subject):" /home/user/Mail/Local\ Folders/Inbox
Subject: New Private Message at Unix and Linux Forums
From: "UNIX.COM" <webmaster@unix.com>
Date: Sat, 21 Feb 2015 12:24:09 -0600 (CST)
Subject: Reply to thread 'I want to send an email after cron job'
From: "UNIX.COM" <webmaster@unix.com>
Date: Sat, 21 Feb 2015 14:36:25 -0600 (CST)

For your request, try

* * * * * TS=$(date); /bin/mail -s "wsaler $TS backup finished" jc@ukzone.com

Don't forget to add an e-mail body.

1 Like

Many thanks RudiC. That is exactly what I wanted.

Thank you.

John C

Hi RudiC...
I wander if you can help me a bit further.
What I would like to do now is to create a file with instructions in it, and include it as the BODY of the email.
At the moment I have:

date | /bin/mail -s " $TS Wholesaler TEST backup finished" jc@ukzone.com    

This displays the current date and time in the body of the email.

I would like to have, e.g.

Instructions for restoration | /bin/mail -s " $TS Wholesaler TEST backup finished" jc@ukzone.com    

This of course doesn't work. No body is displayed.

I would like to write the instructions in a seperate file and then include that file in the email as the body.
If this is podssible.

Any help will be appreciated.

John C

$(cat foo.bar;date) | /bin/mail -s " $TS Wholesaler TEST backup finished" jc@ukzone.com

Redirect mail 's stdin from your file:

/bin/mail ....  < instructions.file

Hi Guys...
Thanks for your help.
I couldn't get blackrageous's suggestion to work, probably due to me being thick.
However, I did get RudiC's suggestion to work, with slight modification:

<BODY /bin/mail -s " $TS Wholesaler TEST backup finished" jc@ukzone.com  

BODY being the name of the file containing the instructions.

I now need to make some text BOLD. Can anybody advise me how this is done in the BODY text file.

Many thanks for your help up to now.

John C