[ubuntu] set timezone by command without interact manually

Step 1: use expect instead of bash, install exect and tzdata

sudo apt-get install expect tzdata

Step 2: create a sh file

#!/usr/bin/expect

spawn sudo dpkg-reconfigure tzdata
expect "Geographic area:"
send "12\r"
expect "Time zone:"
send "4\r"
interact

你可能感兴趣的:([ubuntu] set timezone by command without interact manually)