Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 10 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
1  
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 at 15:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.