TZ variable not exported when running from cron


 
Thread Tools Search this Thread
Operating Systems Solaris TZ variable not exported when running from cron
# 1  
Old 01-19-2012
TZ variable not exported when running from cron

Hi,

I have the following executable in cron:

10 * * * 1-5 /apps/bin/dmg_cronlaunch -ENVI ENVIRONMENT -EXE exec -FILE ratespb_sdos_prdf_`TZ=US/Eastern;date +\%Y\%m\%d\%H\%M\%S`.sdos > /tmp/dmg_exec.log.`/usr/bin/date +\%Y_\%m_\%d_\%H:\%M:\%S` 2>&1

Comprised of the following:

/apps/bin/dmg_cronlaunch -ENVI ENVIRONMENT -> launches a set of variables
-EXE executable -> Executes a program
-FILE ratespb_exe_prdf_`TZ=US/Eastern;date +\%Y\%m\%d\%H\%M\%S`.exe -> This is the output file

When I run it from the command line, the output file appears fine (with the US/Eastern time), however when it's running from crontab it seems to ignore the TZ=US/Eastern; command and the file appears with my local timezone. Any help on this?
# 2  
Old 01-19-2012
This is almost to fiddly to follow.

Create a script and place the commands in a executable script which you can run from cron.
Don't forget a shebang line at the top so you definitely run the Shell you want not whatever the default is in cron.

The way yours is behaving is like an old Bourne Shell in which case you would need "export TZ" before "date". It is not unusual for the default Shell in cron to be an old Bourne Shell. Put the commands in a Shell script with approriate shebang line and forget trying to create complex commands on a cron line.

Ps. It always helps to know what Operating System and version you have and what Shell you prefer.
# 3  
Old 01-19-2012
Hi Methyl,

Sorry I'm going to separate the wheat. The issue is only with the TZ variable, so it comes down to this:

00 * * * 1-5 /apps/sum_glob/fo_live/sparse/bin/dmg_cronlaunch -ENVI SUMLDNFOINT2 -EXE export TZ=US/Eastern; echo $TZ > /tmp/date.txt

If I run this form the command line, the /tmp/date.txt file will look something like that:

gbouausr@longmsumu1$> cat /tmp/date.txt
US/Eastern

But If it's launched by cron, it will be like this (my current timezone shows up, TZ variable doesn't change):

gbouausr@longmsumu1$> cat /tmp/date.txt
GB-Eire

This means the TZ variable remains unchanged when I launch it from crontab. Do you know how can I solve this without the help of a script?
# 4  
Old 01-19-2012
In your post #3 the characters "export TZ" get presented as a parameter to main program.

Please please do tell us what Operating System and version you have. It matters for cron.

Anyway assuming you have a cron which invokes old Bourne Shell, the TZ change needs to be first (note that "export TZ=" syntax will be invalid in old Bourne Shell):

Code:
00 * * * 1-5 TZ=US/Eastern; export TZ; /apps/sum_glob/fo_live/sparse/bin/dmg_cronlaunch -ENVI SUMLDNFOINT2 -EXE ; echo $TZ > /tmp/date.txt

I still strongly advise you to do this in a script and to run the script from cron. The basic cron environment is not suitable for actual scripting.
This User Gave Thanks to methyl For This Post:
# 5  
Old 01-19-2012
Thanks! It works this way. I've tried doing it via script before and it worked as well, but I needed the option to do it directly from the cron line.

Sorry, SunOS is 5.8, with Korn shell.
# 6  
Old 01-19-2012
I believe that SunOS 5.8 has the old Bourne Shell as the default for cron.
# 7  
Old 01-19-2012
$> ps -p $$
PID TTY TIME CMD
14600 pts/55 0:01 ksh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris: ldd doesn't find libraries in exported environment variable LD_LIBRARY_PATH

I have given the relevant details below. Why are the libraries in /export/home/builds/pc9x_root/960/build/powrmart/pmbuild/bin/SunOS.64.r are invisible to ldd? %setenv ... (3 Replies)
Discussion started by: old_as_a_fossil
3 Replies

2. Shell Programming and Scripting

Use of exported variable

i have to use the exported variable from one script into another script ex : A.ksh # !/bin/ksh chk1=56 export chk1 B.ksh # !/bin/ksh echo $chk1 i have executed the... (6 Replies)
Discussion started by: urfrnddpk
6 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. Shell Programming and Scripting

Store a column from an excel sheet (exported to txt) into a variable

I typically pull a bunch of data via SQL that lists a bunch of users and the server on which they want to access, as well as other attributes, in one row of an excel sheet and the number of rows is directly proportionate to the number of users. I'm trying to write a loop to read each line of the... (2 Replies)
Discussion started by: MaindotC
2 Replies

5. Shell Programming and Scripting

Variable not displaying while running in cron job

hi , While running my script individually the variable is working fine. But when i am running the same script from cron job it's displaying nothing. Can any one comment on this. (4 Replies)
Discussion started by: josephroyal
4 Replies

6. Shell Programming and Scripting

using the exported variable after su

Dear All,How can use a variable which I have exported when I am logged into one user to be used once I su to another user.something like 1.Login to Unix box as user12. export var1="TEST"3. su - user24. User the var1 value ( it should return TEST)I have checked just export does not work. any other... (1 Reply)
Discussion started by: rahulkav
1 Replies

7. Shell Programming and Scripting

Seeing variable which are exported with export

Greeting to all of you! I've small issue related to the variable which we are setting and exporting through scripts, in one of the script there are some variable used but I am not abel to get the detail as where they are set. I tried finding the detail with the help of env but no luck. ... (2 Replies)
Discussion started by: kumarmani
2 Replies

8. UNIX for Advanced & Expert Users

Cron not running

Hello All, I have installed a few crons on a machine. But for some reason the crons just don't run. I have checked the permissions on the files and also restarted the cron daemon. But it doesn't seem ti help. Can anyone suggest any other things I can do to get it running again? Regards,... (6 Replies)
Discussion started by: garric
6 Replies

9. Shell Programming and Scripting

Variables are not getting exported while running the script in cronjob

Hi All Some how, variables are not getting exported while running the script in cronjob. Variable value is coming blank. But the variables are geting the value when the same script I am running manually. Any idea why? When running the script in cron-job ==================================... (7 Replies)
Discussion started by: csaha
7 Replies

10. UNIX for Dummies Questions & Answers

What is the difference between a shell variable that is exported and the one that is

What is the difference between a shell variable that is exported and the one that is not exported? (1 Reply)
Discussion started by: JosephGerard
1 Replies
Login or Register to Ask a Question