redirect crontab jobs output

Hi,

I am trying to redirect crontab jobs' output from email to log file. The crontab output go to root email by default. Changed the crontab files:

30 10 * * 1-5 su - oracle -c xxxxxx > xxx.log

But the output still goes to the email, the specified log file is not generated. Could anyone tell me what is the reason?

Thanks
ebi168Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chris_calabreseCommented:
First, are you sure the file is not generated? If this is root's crontab, the file is probably in /.

Next, you're redirecting only stdout, but the messages are probably mostly on stderr.

Try something like this:
30 10 * * 1-5 su - oracle -c xxxxxx > /some/where/xxx.log 2>&1
0
ebi168Author Commented:
I did use 2 >&1 and specified the directory, forgot to post it.

Also the log file should go to a directory owned by root not oracle, right?
0
chris_calabreseCommented:
Given the above, the file will be written by root. Since root can write anywhere, it doesn't really matter what id owns the directory.

Meanwhile, it looks like you have the right thing in place, so I'm going to guess that you have another cronjob or some such that is running the same thing and generating the email.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

ebi168Author Commented:
But the log file is not generated anywhere. I have rootbk, but it shouldn't run.
0
chris_calabreseCommented:
Weird. Maybe the crontab file is corrupted and this job isn't running or something.
0
ebi168Author Commented:
Sometimes it looks like after you change a cron file, the changes will not take effect immediately. Is this reasonable?
0
rugdogCommented:
changes must be immediate, however if you  "manually" change the crontab file, say, by editing with vi /var/spool/cron/crontabs/root. Then the crond doesn't know the file was changed. you have to edit the cron with crontab -e, so when you're done it signals crond to reload the cronfile.
0
chris_calabreseCommented:
Oops, forgot about that possibility. I guess I'm just so used to using the crontab command.
0
ebi168Author Commented:
I used the text editor of the CDE interface of the unix system, will this reload the cron file. When I use crontab -l, everything is there.
0
ebi168Author Commented:
Also everytime I use crontab -e, I get:

unexpected end of line
This entry has been ignored.

Do you know why?
0
rugdogCommented:
crontab -l just list the contents, but if you didnt edit with crontab -e, you must restart cron  so changes take effect.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rugdogCommented:
try this (if you are in sh, ksh or bash)

EDITOR=vi
export EDITOR
crontab -e

or if in csh
setenv EDITOR vi
crontab -e
0
chris_calabreseCommented:
'crontab -e' not only edits the file, but also kicks the running cron daemon to tell it that the file has changed.
Since 'crontab -l' just lists the file, the fact that the line is in there doesn't mean cron knows that it's in there.

So... The appropriate thing to do is 'crontab -e' the file - even if you don't make any changes, this will tell cron to re-read it (you do have to re-write the file, though).
0
ebi168Author Commented:
I did used

EDITOR=vi
export EDITOR
crontab -e

But everytime I get a your crontab file has an error in it email. However nothing seems going wrong.
0
ebi168Author Commented:
So can I reload cron file by stop and restart the /usr/bin/cron process.
0
rugdogCommented:
yes, restarting cron will reload. now if you get the email with error that's beacuse the command you're executing fails.
can you post the crompete crontab line and the email you get?
0
ebi168Author Commented:
Everything is fine. All jobs run. They said this is probably an old cron bug. Do you agree?
0
CadburyKatCommented:
A robust method for manipulating your cron entry:

crontab -l > /tmp/crontab    This will place the file crontab in tmp which will contain your current crontab
vi /tmp/crontab                   This will edit your crontab(don't forget to wq! {save})
crontab /tmp/crontab           This will activate the crontab file your just changed, and will run from now on (unless you have an error in it)
crontab -l                            Prints out your newly enabled crontab file
rm /tmp/crontab                  Cleans up the residuals
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.