HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
Showing results for 
Search instead for 
Did you mean: 

UTC time format script output different

Go to solution
Super Advisor

UTC time format script output different

I have a script that sources from dual.
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...
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
Honored Contributor

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.
Super Advisor

Re: UTC time format script output different

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