LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-25-2003, 08:06 AM   #1
MaverickApollo
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 57

Rep: Reputation: 15
cron Email


How can I get a cron job that I have set up to email me the output of the commands that run?
 
Old 10-25-2003, 08:58 AM   #2
AltF4
Member
 
Registered: Sep 2002
Location: .at
Distribution: SuSE, Knoppix
Posts: 532

Rep: Reputation: 31
Try something like this:

----------------------------
#! /bin/sh

(
echo Running cron Job ....
ls -la
date
) 2>&1 | mail root
----------------------------
 
Old 10-25-2003, 09:56 AM   #3
pablob
Member
 
Registered: Apr 2003
Location: Madrid
Distribution: RHEL, Kubuntu, Solaris, TRU64
Posts: 382

Rep: Reputation: 31
Usually, all cron jobs route message to the local Inbox of the user running the job. I.e.: If you run your cron job as root, then root will get all mail messages.

You can check with "mail" command of course. BUT what you want I guess is to receive it in your @domain.com account, don't you ?

You have to use "aliases":

edit /etc/aliases

add your email to the "root" line (or to the user under which you run your cron jobs). I.e.:

root name@yahoo.com
alfred name@yahoo.com

- Save the file and run "newaliases" command:

root@mymachine # newaliases
root@mymachine #


Now you are done.
 
Old 10-26-2003, 04:49 AM   #4
MaverickApollo
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 57

Original Poster
Rep: Reputation: 15
I thought it should email automatticly. It's not however.

All I did to set up the cronjob is create a script in the cron.daily directory. How can I tell which user account it runs under? I am a newbie!

I will try the first suggestion, as the second dos'nt really apply in this case.
 
Old 10-26-2003, 04:53 AM   #5
MaverickApollo
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 57

Original Poster
Rep: Reputation: 15
Sorry, it may help if I post the file contents!

Here is my cron job


#!/bin/sh

/usr/bin/sa-learn --spam --rebuild --mbox /var/spool/mail/salearn



Is that correct?
 
Old 10-26-2003, 07:16 AM   #6
pablob
Member
 
Registered: Apr 2003
Location: Madrid
Distribution: RHEL, Kubuntu, Solaris, TRU64
Posts: 382

Rep: Reputation: 31
-First I'd try to check if your job is really executing.
-Then we'll check if it mails or not.

For the first, add "2>&1>/tmp/kk.log" to your command:

#!/bin/sh

/usr/bin/sa-learn --spam --rebuild --mbox /var/spool/mail/salearn 2>&1>/tmp/kk.log

If the job is executed, would create a file (kk.log) in /tmp directory with the results of the command. There you can look for explanations.

When the cron execution is confirmed, you'd step to the mail concern.
 
Old 10-26-2003, 10:00 AM   #7
MaverickApollo
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 57

Original Poster
Rep: Reputation: 15
I'll do that, but it has run, because it was set to delete a file, which it did, I later took that line out to correct a error.....

Lets see if kk.log is created!!!!

Thanks for the help, we'll get the mail working later!

Mike
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make cron not send email? bbeers Slackware 7 11-11-2005 11:31 AM
cron job email results... ryedunn Linux - General 7 01-26-2005 11:27 PM
How to retrieve email from cron scripts ? wallywood Linux - General 1 03-05-2004 04:34 PM
Cron job , send email mikeshn Linux - General 1 09-21-2003 10:02 AM
Cron Email Notification(?) jamesyreid Linux - General 2 12-17-2001 11:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:38 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