1847996 Members
7550 Online
104022 Solutions
New Discussion

Re: Time Output

 
Chin Jin Kiat
Occasional Contributor

Time Output

This is boggling, any explanation would be much appreciated.

On a server, running the following:

# ssh username@hostA "env | grep TZ"

... produces no result, yet:

# ssh username@hostA "echo $TZ"

gives the timezone. How can the TZ variable be set and yet not reflected in "env"?
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Time Output

I not an expert on this aspect.

Try this though:

Try loading the environment in the command line

ssh username@hostA "./etc/profile;.$HOME/.profile;env | grep TZ"

I'm interested in the result. Seeme the environment appears not fuly loaded
I've had to do environment loads prior to running scripts in ssh mode. There may be a command line option to force the load. I'm checking.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sanjiv Sharma_1
Honored Contributor

Re: Time Output

Hi Chin,

Please check this link:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=78306

hth.
Everything is possible
Chin Jin Kiat
Occasional Contributor

Re: Time Output

Hi,

Thanks so far but it didn't help situation.

To further elaborate:

1. Both commands essentially does a ssh connection to "hostA" and runs the command "env| grep TZ" and "echo $TZ".

2. Now, if TZ was not set in one case, as shown by "env | grep TZ", it should not show not show up in the 2nd command either via "echo $TZ". Which is the bit which I have no explanation for.

Chin Jin Kiat
Occasional Contributor

Re: Time Output

Stev,

Your suggestions gave me further ideas for testing.

# ssh username@hostA ". /etc/profile;. $HOME/.profile;env | grep TZ"

>> Shows TZ in "env".

ssh username@hostA ". $HOME/.profile;env | grep TZ"

>> TZ setting in "env" is gone.

Still probing, thanks for all help so far.


Jdamian
Respected Contributor

Re: Time Output

The answer to your question is:

A variable only is listed by 'env' command when that variable has been exported. For instance, see carefully the two next examples:

# first example. Output is empty
HPHPHP=hello
env | grep '^HPHPHP'

# second example. Output is
export HPHPHP=hello
env | grep '^HPHPHP'
HPHPHP=hello

Other issue is what your second command line prints a TZ value. This is due because that value is not from 'hostA', but from the computer you launch the ssh command (let's call it 'myhost'). Before running the ssh, shell running in 'myhost' substitutes "$TZ" for its value, then (for instace TZ variables contains the value UTC),the command executed is:

# ssh username@hostA "echo UTC"

To see the value of TZ variable in hostA you should use single quotes instead:

# ssh username@hostA 'echo $TZ'

I hope this be useful.