cron as user 'oracle' works for some tasks, not for others
Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cron as user 'oracle' works for some tasks, not for others
Hi,
I'm an oracle dba and have been pulling my hair out trying to figure out why certain cron jobs are not working while others do. It has to be an environment issue but I still can't figure it out. I have two cron jobs that work fine, each one calling a .ksh script and then appending >> the output to a log file. Both scripts call sqlplus and perform a few tasks within the database.
Below those two tasks, I have been trying to clean up my log files by zipping or tar them (neither work), then in a separate cron delete log files older than an week. So I'm trying to use zip,gzip,tar,find,rm (that I can think of). All of these tasks can be done outside of cron. At the very top of my crontab I execute the .bash_profile for oracle via '. /home/oracle/.bash_profile'.
After googling the problem, I tried to locate any logs of the problem and all I see is the actual command, no ouput past that point. For example, I would see that at 2300 my tar cron statement was executed but nothing other than that. Nothing gets done and nothing gets written to a log file even if I try to append the output to a file. Any help appreciated. RHEL5 64bit, oracle is in cron.allow.
The first two work, the last 3 do nothing. Thanks again for any help.
Forgot the first line, this is at the top:
* * * * * . /home/oracle/.bash_profile
The first two work, the last 3 do nothing. Thanks again for any help.
Forgot the first line, this is at the top:
* * * * * . /home/oracle/.bash_profile
The % sign is special when seen from cron. Try escaping them:
Code:
00 02 * * 0 tar -czf tracesid1_$(date +\%y\%m\%d).tar.gz /opt/app/oracle/trace/SID1_*
15 02 * * 0 tar -czf coresid1_$(date +\%y\%m\%d).tar.gz /opt/app/oracle/trace/cdmp*
Not sure why the third one doesn't work (probably something similar as the other 2).
In general: Don't put commands + options in cron. Put the command and options in a wrapper script and use that wrapper script in cron.
Last edited by druuna; 01-24-2013 at 07:43 AM.
Reason: fixed typo
The most common problem when using cron to run a script: the environment isn't parsed when running from cron.
You only post a global problem sketch and no details, so I cannot point you to something specific.
One way to make sure that your (user) profile is parsed when running a script from cron is doing something like this:
Code:
#!/bin/ksh
# running from cron?
[[ "`/usr/bin/tty`" == "not a tty" ]] && . ~/.profile
# rest of the code
If I enter this, it won't let me save the crontab. I copied it into notepad just to make sure I had everything right and it still won't let me save it.
1. don't put cmds in crontab, put shell/perl/whatever scripts that do what you want.
2. cron env is minimal; in the shell scripts, specify complete paths to all cmds and files OR at the top of the script, explicitly call the relevant env setup file OR hard code env
3. use built-in tool logrotate to deal with log file trimming (any similar files also) http://linux.die.net/man/8/logrotate
4. as above, '* * * * * . /home/oracle/.bash_profile' is completely pointless
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.