LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-20-2016, 02:24 PM   #1
YouOverThere
LQ Newbie
 
Registered: Dec 2016
Posts: 1

Rep: Reputation: Disabled
date: shell vs. cron. Why aren't they the same?


Like most scientific organizations, we specify time in UTC. Recently, a program that is run from the cron started using the wrong time. I discovered that the 'date' command was now outputting EST instead of UTC. I then discovered that the current version of /etc/localtime on this machine was installed the day that the behavior of 'date' changed and that /etc/localtime is now a link to /usr/share/zoneinfo/US/Eastern. Now for the confusing part: 'date' still outputs UTC when not run in a cron job. Whether I type in 'date' or put 'date' in a C shell script, I get UTC. But if I run that same C shell script as a cron job, it switches to EST. I can accept that the new /etc/localtime changed the behavior of 'date', but I don't understand why the change only occurs in cron jobs. Can anyone explain this?

(the environment variable TZ on this machine is set to UTC0.)
 
Old 12-20-2016, 03:53 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Probably because for your logged in user you are setting TZ to UTC0 in one of the profiles (.bashrc, /etc/profile ....) but the cron job is getting a minimal environment that doesn't set TZ at all so it is using the /etc/localtime.

Have a look at:
http://www.linuxquestions.org/questi...-script-36931/

You can set the TZ explicitly in your cron job OR revert your /etc/localtime to use the one for UTC.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
cron is running but jobs aren't kalahari875 Mandriva 4 03-15-2006 03:47 PM
You aren't running in a login shell. ? Odd error esears Linux - Software 1 05-20-2004 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration