I want to send an email after cron job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I want to send an email after cron job
# 1  
Old 02-21-2015
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:
Code:
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:
Code:
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
# 2  
Old 02-21-2015
Wouldn't the mail's source text contain that time stamp?
Code:
grep "^Date:" mailfile
Date: Sat, 21 Feb 2015 12:24:09 -0600 (CST)

# 3  
Old 02-21-2015
Hi RudiC...
Thanks for your reply.
Quote:
Wouldn't the mail's source text contain that time stamp?
Yes it would. However, the emails will be listed and I want to see the date in the SUBJECT line. i.e.
Code:
date | /bin/mail -s "wsaler the curent date and time backup finished" jc@ukzone.com

This shows in the email Subject:
Quote:
wsaler the curent date and time backup finished
I want it to read
Quote:
wsaler Sat Feb 21 18:00:01 GMT 2015 backup finished
I hope this makes it clearer what I am trying to achieve.

Thanks,

John C
# 4  
Old 02-21-2015
Well understood. Still you could use grep on your mail file:
Code:
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
Code:
* * * * * TS=$(date); /bin/mail -s "wsaler $TS backup finished" jc@ukzone.com

Don't forget to add an e-mail body.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 02-21-2015
Many thanks RudiC. That is exactly what I wanted.

Thank you.

John C
# 6  
Old 02-23-2015
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:
Code:
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.
Code:
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
# 7  
Old 02-23-2015
Code:
$(cat foo.bar;date) | /bin/mail -s " $TS Wholesaler TEST backup finished" jc@ukzone.com

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script that will send an email if the cron job did not run.

Team, Would like to know what is the best script that will send you an email if cronjob did not run. Thanks (4 Replies)
Discussion started by: kenshinhimura
4 Replies

2. Solaris

Solaris cron job email generation not required

Hi, How do we stop default cron job emails bein generated in Solaris 10? All our cron entries are ending with /dev/null 2>&1 but still emails are being generated. And all these emails are nuisance, as they are also get relayed to our local network sendmail MTA server (for system email... (14 Replies)
Discussion started by: hasan.kamali
14 Replies

3. Shell Programming and Scripting

how to run a script using cron job and send the output as attachment via e-mail using unix

how to run a script using cron job and send the output as attachment via e-mail using unix. please help me. how my cron job entry should be? As of now my cron job entry is to run the script at specific time, 15 03 * * * /path/sample.sh | mail -s "Logs" email_id In the above entry, what... (8 Replies)
Discussion started by: vidhyaS
8 Replies

4. Shell Programming and Scripting

how to avoid cron job output to send to the junk email folder?

Hi i created a cron job which invoke a shell script and output some content via email. Some times these output are sent to the junk email folder. i want these mails to be sent to inbox with some specific font. what i have to do? (4 Replies)
Discussion started by: vidhyaS
4 Replies

5. Shell Programming and Scripting

Send a file through email using cron as an attachment

Hi All, I want to send a file as an attachment through cron job.Is this possible using cronjob nd if it i, can you please let me know how to do this? Thanks (2 Replies)
Discussion started by: NARESH1302
2 Replies

6. Shell Programming and Scripting

Echo print in different lines within email sent by Cron job

Hi all, I think this could have a simple solution, just I canīt get it so far. I have the script below that includes several echo commands in order to show that every part of the script have been executed. A cron job executes this script and when is completed the output is sent by email. ... (4 Replies)
Discussion started by: cgkmal
4 Replies

7. Shell Programming and Scripting

Send an email once a job is completed

Hi, The HPCs I used earlier used PBS (Portable Batch System) to schedule when I was running various jobs and it had an option to send me an email once a job is completed. I'm wondering whether this is possible for any other process (without the use of PBS). For example, I'm running some codes... (2 Replies)
Discussion started by: lost.identity
2 Replies

8. Shell Programming and Scripting

Cron Job Automated Email Alternatives?

Hi guys, not sure if this would be the right place for this but I dont where else it would go... I'm new to Unix too, so please bare with me :) I guess first up some background on the situation. We have some scripts that run as cron jobs which monitor and check the health, etc of our servers.... (2 Replies)
Discussion started by: BrianD
2 Replies

9. AIX

Cron Job notification email

Hi, I'm fairly new to Aix and am looking for some help on the following. I have setup a cron job under root and want it to send the email once it's run to an external email address. I can get it to send the output in an email to me by using mail on the end of the crontab entry. But I would... (1 Reply)
Discussion started by: elmesy
1 Replies

10. Solaris

Sun Solaris version 10: cron job does not send the default message.

Hi all, Our servers were on Sun Solaris 8.1, anytime a cron job executed the user ran that job received a email of job's output. I think that the default and Administrator did not setup anything. However, when we upgraded the OS to Sun Solaris ver.10, the cron job is no longer send a email... (2 Replies)
Discussion started by: cmnguyen
2 Replies
Login or Register to Ask a Question