Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set up a script that automatically changes the timezone on a machine (running ubuntu 11.10) and also sets the right values to the debconf database. I've tried the following, but it does not work (at the end, the current timezone remains unchanged, and if I run manually the dpkg-reconfigure tzdata command, the selected values are indeed the old ones):

#!/bin/sh -e
echo "tzdata    tzdata/Areas    select  Europe" | debconf-set-selections
echo "tzdata    tzdata/Zones/Europe select  Madrid" | debconf-set-selections
echo "tzdata    tzdata/Zones/America    select  " | debconf-set-selections
dpkg-reconfigure -f noninteractive tzdata

So, by now, I'm doing it messing with the files /etc/localtime and /etc/timezone directly, but I'd rather prefer the dpkg-reconfigure and debconf way.

share|improve this question
up vote 22 down vote accepted

Simplest way that I know of is:

echo "Europe/Zurich" > /etc/timezone 
dpkg-reconfigure -f noninteractive tzdata
share|improve this answer
Thank you, that works for all my requirements :) – Carlos Campderrós Nov 19 '12 at 8:37
wbat do the parameters to dpkg-reconfigure mean? – serengeti12 Jan 11 '13 at 0:02
Be aware that running processes may not pick up the change without a restart. Eg log timestamps from server daemons are likely to be wrong until you restart the daemons. – mc0e Mar 4 '14 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .