Setting the Timezone with an automated script
Posted
by Tom
on Server Fault
See other posts from Server Fault
or by Tom
Published on 2009-12-16T15:57:53Z
Indexed on
2010/03/25
10:23 UTC
Read the original article
Hit count: 398
I'm writing scripts to automate setting up new slicehost installations. In a perfect world, after I started the script, it would just run, with no attention from me. I have succeeded, with one exception.
How do I set the timezone, in a permanent (survive reboot) and sane (adjust for standard and daylight savings time, so no just forcing the date) ... manner that doesn't require input from me?
Currently, I'm using
dpkg-reconfigure tzdata
This doesn't seem to have any way to force parameters into it. It demands user input.
EDIT: I'm editing here, rather than commenting, since comments don't seem to allow code blocks.
Here's the actual code I ended up with, based on Rudedog's comment below. I also noticed that this doesn't update /etc/timezone. I'm not certain who uses that, but in case anybody does, I'm setting that too.
TIMEZONE="America/Los_Angeles"
echo $TIMEZONE > /etc/timezone
cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime # This sets the time
© Server Fault or respective owner