PDA

View Full Version : Sending cron reports to mail


pyrogen
03-17-2002, 01:44 PM
Hello everyone....... I'm very new to UNIX and have encountered a problem following a simple tutorial.

http://www.oreillynet.com/lpt/a//mac/2001/12/14/terminal_one.html

I had no problem altering the times in my crontab for the daily monthly and weekly cronjobs. But when I tried to get the reprots sent to my local unix mail acount, it never shows up.
Does anyone know how I could make this work?
Is there a way to check ones daily-weekly-monthly- cron reports in the terminal? (I would need detailed steps please, I'm still learning)
Very grateful for any help,
Thanks,
Destin

mervTormel
03-17-2002, 02:16 PM
But when I tried to get the reprots sent to my local unix mail acount, it never shows up.
what did you try? the easiest way is to forward all of root's email to your account...
$ sudo cat /var/root/.forward
yourAccount
that was in o'reilly's c.stone's terminal part 2...

http://www.oreillynet.com/pub/a/mac/2002/01/22/terminal_pt2.html

as for the logs for the cron jobs we are speaking of, you can look them up thusly:

$ ll /var/log/*.out
-rw-r--r-- 1 root wheel 1.6k Mar 17 00:17 /var/log/daily.out
-rw-r--r-- 1 root wheel 144 Mar 10 22:25 /var/log/monthly.out
-rw-r--r-- 1 root wheel 163 Mar 17 00:22 /var/log/weekly.out

pyrogen
03-17-2002, 02:50 PM
Ignore this please.
Please check the post below.

pyrogen
03-17-2002, 06:27 PM
Please correct me if I'm wrong.........
I changed the roots .forward file from /dev/null (back hole), to my account name.

[localhost:~] chris% cd ~root
[localhost:~root] chris%


[localhost:~root] chris% sudo pico .forward

//changed foots forward from /dev/null to my account name.

^o
^x
// write and then exit

[localhost:~root] chris% sudo chmod g-w /

// to get sendmail going

I can now send the command line mail root
and send messeges and check them when I open the terminal,
However, will I recieve the cron reports through this mail box?
I had attempted to follow the rest of the tutorial, which insrtucts you how to have the cron reports sent to a gui mail I created, but it only transfer my message once to the gui mail (created unix mailbox that was local)

I'm not sure what I did wrong.

PS
I did try to run both of your suggestions,
1) Is what I did above basically the long way to accomplish ?

$ sudo cat /var/root/.forward
yourAccount

2) i ran the command

[localhost:~] chris% $ ll /var/log/*.out

// to check my cron jobs in the terminal, but the results looked like this

$: Command not found.
/var/log/*.out: No match.

Am I doing something incorrect?

I apologise if I am asking a painfully easy question, but I am just learning,
please have patience with my ignorance.

I have to resume studying for my final examinations, so if I do not respond to a (response) post immediatly, do not think it is out of inconsideration.

Thank you for your time,
Destin

pyrogen
03-17-2002, 09:28 PM
Yeah!!!!................ I just checked my mail, -in the terminal-, and it contained my daily cron job report. It did not show up in my GUI unix account, however, but who cares, I can just check it the terminal from now on.

by the way, when you check your mail in the terminal
( it says "mail for -username-")
// in the command line I type "mail"
// I check the mail, blah blah blah......
// and i type "q" in the command line.
// the response from darwin "message saved in mail box".

A few questions.......

1) How do I erase this accumilating mail?
2) Does the mail actually accumilate?
3) Is there a more appropriate response for the command line than "q" ( for example a prompt that would erase that mail ie. not save it?)
4) Is it important to save this mail ( the cron job reports)?

I am still very curious about the questions from my previous post.
If any one can help,

And thanks to everyone for the help so far,
Destin

mervTormel
03-17-2002, 10:00 PM
the contents of a .forward file is any valid email account, one per line. a valid username on a local machine constitutes a valid email address.

$ cat .forward
localUsername
username@isp.com

[localhost:~] chris% $ ll /var/log/*.out
$: Command not found.
/var/log/*.out: No match.

try issuing the ll command without the dollar sign ($). the dollar sign is my shell prompt. your shell prompt ends with % . most UNIX command line work begins with a command name, like ll, which is shorthand for ls -l

pyrogen
03-17-2002, 10:33 PM
//is the command

% sudo pico .forward

// then add , in the pico editer

localusername

username@mac.com

// the same as doing

% cat .forward
localusername
username@mac.com

// just curious

So i can have my cron reports sent to multiple local addresses, just as long as i enter each address on it's own line?

Thanks again,
Destin

mervTormel
03-17-2002, 11:33 PM
sorry, pyrogen, you've got some reading to do if you want to persue this business. follow along here...

% man man
% man sudo
% man pico
% man cat

man is the command for listing manual pages for commands. just skim the man pages to get a jist of a command, then refer back to it when you want to know more.

sudo is a command that allows you to switch to being superuser (or any user) for a command line

pico is a generally simple text editor

cat is a command to display a file

/var/root/.forward is a file belonging to the root user, and only readable/writable by root, not you, so you have to access it under the guise of sudo so you can read it and write it (save it)

the contents of a .forward file is just where to forward the email to, one entry per line, or /dev/null to vaporize an email.

pyrogen
03-18-2002, 12:02 AM
Thank you for the information, ............and the patience.

I'm off to dig through the man files,
Thanks again,
Destin

mervTormel
03-18-2002, 01:11 AM
your welcome.

i mentioned pico as it seemed to be a good introduction to this simple editor, which is good for beginners to know.

but there are many ways to feed a file in UNIX. most everything in UNIX is a file, so most commands and operators can be turned on files.

to create a .forward file, you could:

% cat > .forward
account@isp.com
^D
%

here, cat reads from stdin (the keyboard) and redirects ( > ) its input to the file .forward - a control-D ( ^D ) signals end-of-file

or

% echo "account@isp.com" > .forward

echo writes its argument, and here it is redirected to the file .forward

in tcsh, the sudo echo won't work because the redirect to .forward is opened in the parent shell, before the sudo echo sub-shell. there's some jiggery-pokery to get this to work, but it's easier to su root to get the job done.

caveat: Destin, be very careful issuing commands as root, as there are no protections. even UNIX veterans occasionally screw the pooch, as root. you'll see these kinds of warnings of varying degrees of whininess from time to time. warnings are like traffic signs. they are suggestions and you can disregard them as you like.

at_sym
03-18-2002, 02:16 AM
I've also set up cron to email daily reports, and I was curious about how sendmail is behaving. I have .forward set to mail reports to an email address on another server. When the Mac sending the cron jobs had a static IP, everything worked fine. I had to change to a DHCP-distributed email address recently. Since then, the report is prefaced with an error message:

----- The following addresses had permanent fatal errors -----
[email address in .forward]
(reason: 572 <root@localhost> domain does not exist)
(expanded from: root)

----- Transcript of session follows -----
... while talking to [.forward address's email server].:
>>> MAIL From:<root@localhost>
<<< 572 <root@localhost> domain does not exist
554 5.0.0 [email address in .forward]... Service unavailable

Reporting-MTA: dns; localhost
Arrival-Date: Sun, 17 Mar 2002 22:17:09 -0800 (PST)

Final-Recipient: RFC822; root@localhost
X-Actual-Recipient: RFC822; [email address in .forward]
Action: failed
Status: 5.0.0
Diagnostic-Code: SMTP; 572 <root@localhost> domain does not exist
Last-Attempt-Date: Sun, 17 Mar 2002 22:17:25 -0800 (PST)

Any idea for a fix? Thanks!

pyrogen
03-18-2002, 03:55 AM
This may sound stupid but.......

when I want to edit .forward to include my email address (my mac.com address, which is a pop mail) what do I write to .forward exactly?

I'm using pico editer

[localhost:~] chris% cd ~root
[localhost:~root] chris%
// then
[localhost:~root] chris% sudo pico .forward
password:

//then I'm inside pico editer......... it just shows my username. (I'm using the
//name chris just to illustrate.

chris

// now, do I just add my email address below the username? example

chris
pyrogen@mac.com

(I did try this , but it returned a error message simular to the error message At_syms posted)
I noticed that your post indicated 'account@isp.com' isp = internet service provider? I'm sorry this question is so rudimentary, but I really don't know.
maybe this is where I am making a critical error.

I figured out how to make the prompt

% || var/log/*.out

work properly. The shell wasn't recognizing "||", so I used "ls -l" instead.
% ls -l /var/log/*.out

Worked perfectly!
I've learned so much today, thanks again for all of your help,
Destin

pyrogen
03-18-2002, 12:50 PM
if I use the pico editor, I can alter the .forward file.

OR

if I use the prompt:

% echo "account@isp.com" > .forward

echo writes it's argument "account@isp.com", and ">", redirects the argument to ".forward".

and I effectively change the contents of ".forward".

Correct?

So what information from my email account do I place in the echo argument?

Good sense tells me this is wrong:

% echo "pyrogen@mac.com" > .forward

Sorry to keep bothering you,
Thanks,
Destin

mervTormel
03-18-2002, 03:49 PM
correct. unless the noclobber shell variable is set. noclobber prevents you from overwriting existing files.

your good sense is broken. your echo is correct. once again, a valid line in a .forward file is a valid email address (among other things).

consider:

$ sudo cat /var/root/.forward
merv

$ cat ~/.forward
myEmail@myISP.com
myYahoo@yahoo.com


here, we see that root's email is forwarded to my local OSX account, and that my .forward takes care of distributing the email to my isp email and my yahoo throwaway account.

BTW, you can test command line things if you're curious...

% cd
% echo "test" > foo
% cat foo
test
% echo "test2" >> foo #comment: >> appends to an existing file
% cat foo
test
test2
%

pyrogen
03-19-2002, 12:58 AM
The addresses I added to ".forward" are not working. I sent a test mail to root, and when iI checked it , it sayed I had an error:

----- The following addresses had permanent fatal errors -----
pyrogen@mac.com
(reason: <katherin@localhost>... Real domain name required for sender address)
(expanded from: katherin)

What's wrong?

when I check .forward.....

% cat /var/root/ .forward

pyrogen@mac.com
katherin
infinitedisco@hotmail.com

every thing seems in order........

any suggestions?

Thanks,
Destin