General
cancel
Showing results for 
Search instead for 
Did you mean: 

UTC time format script output different

SOLVED
Go to solution
Ratzie
Super Advisor

UTC time format script output different

I have a script that sources from dual.
SELECT TO_CHAR(CURRENT_DATE,'DD-MON-YY-HH24:MI:SS')
FROM dual

If I run this from command line I get the time in UTC, just like the rest of the time stamps for the script...
IE:
SELECT TO_CHAR(capture_message_create_time,'DD-MON-YY-HH24:MI:SS')
FROM v\$streams_capture

So the output would look like:
14-JAN-09-16:00:00 14-JAN-09-15:59:58

But if I run from cron...
Out put is:
14-JAN-09-10:00:00 14-JAN-09-15:59:58

Which is 6 hours out.
I source my environment in my script and TZ=UTC.

So why the difference, and how do I make it all the same?

I would like it all in either UTC, or all -6 CST
2 REPLIES
TTr
Honored Contributor
Solution

Re: UTC time format script output different

The cron environment is different than that of the command line. When you run the same script from cron you have to set the user environment just like it is in the command line. I am guessing this is a database account (oracle?) so when you run this script from cron you need to initialize all the variables as they are when you login to this account on the command line. If this is indeed an oracle account you need all the oracle parameters such as ORACLE_HOME, SID, TNS etc. When you are on the unix shell command line type in the "env" command and see all the variables that have been set. Most of these are NOT setup when running in cron.
Ratzie
Super Advisor

Re: UTC time format script output different

Thought I did, but didn't...
Had to add TZ=UTC in my script.