[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

redirect crontab jobs output

Posted on 2004-11-12
18
Medium Priority
?
8,281 Views
Last Modified: 2013-12-27
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
0
Comment
Question by:ebi168
  • 8
  • 5
  • 4
  • +1
18 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12569056
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
 

Author Comment

by:ebi168
ID: 12569118
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
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12569217
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ebi168
ID: 12569408
But the log file is not generated anywhere. I have rootbk, but it shouldn't run.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12569427
Weird. Maybe the crontab file is corrupted and this job isn't running or something.
0
 

Author Comment

by:ebi168
ID: 12569746
Sometimes it looks like after you change a cron file, the changes will not take effect immediately. Is this reasonable?
0
 
LVL 7

Expert Comment

by:rugdog
ID: 12569827
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
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12570007
Oops, forgot about that possibility. I guess I'm just so used to using the crontab command.
0
 

Author Comment

by:ebi168
ID: 12570046
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
 

Author Comment

by:ebi168
ID: 12570128
Also everytime I use crontab -e, I get:

unexpected end of line
This entry has been ignored.

Do you know why?
0
 
LVL 7

Accepted Solution

by:
rugdog earned 420 total points
ID: 12570138
crontab -l just list the contents, but if you didnt edit with crontab -e, you must restart cron  so changes take effect.
0
 
LVL 7

Expert Comment

by:rugdog
ID: 12570161
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
 
LVL 14

Assisted Solution

by:chris_calabrese
chris_calabrese earned 180 total points
ID: 12570202
'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
 

Author Comment

by:ebi168
ID: 12570285
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
 

Author Comment

by:ebi168
ID: 12570312
So can I reload cron file by stop and restart the /usr/bin/cron process.
0
 
LVL 7

Assisted Solution

by:rugdog
rugdog earned 420 total points
ID: 12570362
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
 

Author Comment

by:ebi168
ID: 12570793
Everything is fine. All jobs run. They said this is probably an old cron bug. Do you agree?
0
 
LVL 2

Expert Comment

by:CadburyKat
ID: 12722712
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question