Operating System - HP-UX
1834287 Members
2014 Online
110066 Solutions
New Discussion

Redirect cron output containing SQL results

 
SOLVED
Go to solution
Beannie
Advisor

Redirect cron output containing SQL results

Trying to get cron output redirected to separate file (for mailing). Problem is the script contains sql and oracle procedures and when I try normal redirecting (ie > /tmp/out or > /tmp/out 2>&1), I either get nothing or "ERROR: ORA-12154: TNS:could not resolve service name.. Invalid option. Usage: CONNECT [AS SYSDBA|SYSOPER]". We have to use the script as is, cannot break it up into separate portions (script, sql, procedure). Basically put, want to place the same cron output showing up in /var/mail/CRON for this particular job in a separate file also. Thanks ahead of time. This is a great resource.
4 REPLIES 4
John Palmer
Honored Contributor
Solution

Re: Redirect cron output containing SQL results

Hi,

I can't think why redirecting the output should cause this, cron only redirects output to a temp file in any case and mails you the results.

Instead of running the script directly from cron, have you tried cronning a wrapper script which redirects output and then calls your original?

Regards,
John
A. Clay Stephenson
Acclaimed Contributor

Re: Redirect cron output containing SQL results

My best guess is that this has nothing to do with output redirection and everything to do with environment. Cron has an intentionally very sparse environment. You need to define and export any needed environment variables within your cron wrapper script. You don't want to do a su - username ... to load the environment because username's .profile almost certainly has interactive commands like stty and tabs which will fail in stdin is not a terminal.

If it ain't broke, I can fix that.
Beannie
Advisor

Re: Redirect cron output containing SQL results

Hi;
Thanks for the fast feedback... Have not tried wrapper scripts and going to pursue that direction (in cron)... am ready for a new challenge! Pulled some very good info on them from this forum and will be careful to define/export environment variables as well. May be a couple days but will post my outcome. Thanks again :-) Julie
Beannie
Advisor

Re: Redirect cron output containing SQL results

Hi all, The wrapper script worked and gave me what I needed... a return status code. Will now move forward to an e-mail notification based on the return status code. Thanks again for the idea. My scripting skills gradually get better, alot of thanks go to this forum and everyone that contributes to it. Enjoy, Julie :-)