开发者

How do I set remote server TimeZone via Fabric?

I'm trying to change my remote server's timezone via Fabric like so:

run("export TZ=\":Pacific/Auckland\"")
run("date")

This doesn't 开发者_StackOverflowseem to work. run("date") gives me: Tue Apr 19 00:19:58 CDT 2011 which is not the timezone I just set.

If I just log into the server and run the same bash commands, everything's just as expected:

[lazo@lazoweb]$ date
Tue Apr 19 00:20:00 CDT 2011
[lazo@lazoweb]$ export TZ=":Pacific/Auckland"
[lazo@lazoweb]$ date
Tue Apr 19 17:20:20 NZST 2011

Can anyone shed some light on this? What am I missing?


run("export TZ=\":Pacific/Auckland\"")
run("date")

is like

/bin/sh -c 'export TZ=":Pacific/Auckland"'
/bin/sh -c 'date'

You're launching a shell, setting one of its environment variables, then exiting it. It never had a chance to pass that environment var to anyone.

Set TZ in your script's environment then run date. I don't know Python, but it seems to be

os.environ['TZ'] = ":Pacific/Auckland"
run("date")


For the reasons ikegami explained about the environment, the two separate commands will not work. However, you can achieve what you desire with:

run("TZ=':Pacific/Auckland' date")


This only works for the current shell. Close the shell, start a new one and type date, you will see that the TZ has reset to the default timezone. Even for Fabric if you capture the output, you'd see that the TimeZone does get set correctly but as the script ends, so does the shell and hence the TZ variable is no longer available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜