TZ variable not exported when running from cron


 
Thread Tools Search this Thread
Operating Systems Solaris TZ variable not exported when running from cron
# 8  
Old 01-20-2012
To find out, make a one-off cron containing say:
Code:
env > /tmp/env.lst

It is surprising how sparse the cron environment is.
# 9  
Old 01-20-2012
The supported and documented way is to set the TZ variable before the crontab command line. eg:
Code:
...
TZ=US/Eastern
10 * * * 1-5 /your/command here

This also affects how the date and hour specifications are to be interpreted.
# 10  
Old 01-20-2012
That would affect everything in the crontab, though, not just the one.

Can you specify any environment there, or only TZ?
# 11  
Old 01-20-2012
That would affect subsequent lines until TZ is set to another value.

TZ, SHELL and HOME are the environment variables that can be set this way.

However, I just noticed I overlook this is about Solaris 8 with which I'm afraid this syntax wasn't yet supported ...

Edit: I confirm this syntax is only supported by SunOS 5.11 based OSes (OpenSolaris, Solaris 11). Sorry for the confusion.

Last edited by jlliagre; 01-20-2012 at 06:32 PM..
# 12  
Old 01-20-2012
In a system where the users are in multiple timezones we would set the system clock to UTC and source a local environment script at the top of every user script (whether or not it was strictly necessary). The local environment script sets TZ, any local character sets, and a Country Code Environment Variable for the benefit of database programs which have variable currency or geography.

Long and complex crons are a maintenance nightmare. Avoid.

Imho Organise a crontab by function and write a script to display them in time order.
# 13  
Old 01-20-2012
At least on Solaris, the system clock is always set to UTC. Having a default timezone set to UTC too, which is I guess what you really mean, might confuse (unaware) people editing crontabs as they probably expect its timezone to be set to the server location local time.
Cloud computing and migrating virtualized OSes, on the other hand, might defeat the very notion of server location ...
# 14  
Old 01-23-2012
Yes, I checked using env as well:

SHELL=/bin/ksh


Thanks, I've solved it using a script from the cron line, I also understand it's a bit messy trying to script from the cron line.
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