亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4502 | 回復(fù): 1
打印 上一主題 下一主題

RHEL時區(qū)設(shè)置(Time Zone in RHEL) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-11-24 17:11 |只看該作者 |倒序瀏覽
本帖最后由 chinaux 于 2011-11-25 08:24 編輯

Environment: RHEL 6.1

How to set a correct time zone  in RHEL could  be a headache issue, it was for me a few days ago. For system administrators in China, most of them have no such an issue, since they may do a simple "ln -sf /usr/share/zoneinfo/PRC /etc/localtime" or "cp -a /usr/share/zoneinfo/PRC /etc/localtime", and then a correct timezone is on the output of "date" or "date +%Z". However, what to do if I'd like to see "GMT+8"?

"ln -sf /usr/share/zoneinfo/Etc/GMT+8 /etc/localtime" does give the correct time zone "GMT+8", however, the time is completely wrong, it's the time of US/Pacific. "ln -sf /usr/share/zoneinfo/Etc/GMT-8 /etc/localtime" gives me the right time, however, the time zone "GMT-8" is not what I expect.

"export TZ=GMT-8" in bash gives the correct time, but, the time zone "GMT" is still incorrect.

The right solution is .........

export TZ="<GMT+8>-8"

then, both the time and the time zone are correct!


I've written functions of setting a time zone in system-wide in bash for your reference:
  1. backup_file()
  2. {

  3. file=$1

  4. tmpbackup=${file}.tmp

  5. if [ ! -f $file ]; then
  6. #       echo "File $file doesn't exist." >&2
  7. #       return 1
  8.         touch $tmpbackup
  9.         restorecon $tmpbackup
  10.         return 0
  11. fi
  12.   
  13. cp -a $file $tmpbackup

  14. if [ "X${backup}" == "no" ]; then return 0 ; fi

  15. if [ ! -f ${file}.${stamp} ]; then
  16.         cp -a $file ${file}.${stamp}
  17. fi

  18. return $?
  19. }

  20. # compare a configuration file  against its backup ended with "$stamp"
  21. compare_files()
  22. {
  23. file=$1
  24. tstamp=$2

  25. if [ ! -f $file -o ! -f ${file}.${tstamp} ]; then
  26.         echo "Error: either $file or ${file}.${tstamp} doesn't exist." >&2
  27.         echo "Error: fail to compare files." >&2
  28.         return 99
  29. fi

  30. if [ "X$(diff $file ${file}.${tstamp})" == "X" ]; then
  31.         echo "  no changes made to $file."
  32.         rm -f ${file}.${tstamp}
  33.         return 0
  34. else   
  35.         echo "  $file is now regenerated."
  36.         return 1
  37. fi

  38. }

  39. set_timezone()
  40. {

  41. timezone=$1

  42. if [ "X${timezone}" == "X" ]; then
  43.         echo "Error: timezone must be a valid value." >&2
  44.         return 1
  45. fi

  46. echo -e "  new timezone \"${timezone}\" is to be set. "
  47. echo -e "  current timezone is \"$(date +%Z)\" according to the output of \"# date +%Z\". "

  48. backup_file /etc/profile
  49. backup_file /etc/csh.login
  50.         
  51. # bash/ksh
  52. if grep -q "^export[[:space:]]\{1,\}TZ=" /etc/profile; then
  53.         echo "  current TZ is $(grep '^export[[:space:]]\{1,\}TZ=' /etc/profile  | sed -e 's/.*TZ=//' -e 's/#.*//' -e 's/[[:space:]].*//g') on /etc/profile."
  54.         grep -v "^export[[:space:]]\{1,\}TZ=" /etc/profile > /etc/profile.tmp
  55. fi

  56. # csh
  57. if grep -q "^setenv[[:space:]]\{1,\}TZ\{1,\}" /etc/csh.login; then
  58.         echo "  current TZ is $(grep '^setenv[[:space:]]\{1,\}TZ[[:space:]]\{1,\}' /etc/csh.login | sed -e 's/.*TZ[[:space:]]\{1,\}//' -e 's/#.*//' -e 's/[[:space:]].*//g') on /etc/csh.login."
  59.         grep -v "^setenv[[:space:]]\{1,\}TZ[[:space:]]\{1,\}" /etc/csh.login > /etc/csh.login.tmp
  60. fi

  61. echo $timezone | grep -q -E "\+|\-"
  62. if [ $? -ne 0 ]; then

  63.    if [ -f /usr/share/zoneinfo/${timezone} ]; then
  64.         rm -f /etc/localtime
  65.         cp -a /usr/share/zoneinfo/${timezone} /etc/localtime
  66.         echo "  timezone is now set to \"$timezone\"."
  67.    else
  68.         echo "Error: timezone \"$timezone\" is not supported." >&2   
  69.    fi

  70. else

  71.    if echo $timezone | grep -q '+'; then
  72.         offsethour=$(echo $timezone | sed -e "s/.*+/\-/")
  73.    else
  74.         offsethour=$(echo $timezone | sed -e "s/.*-/\+/")
  75.    fi

  76.    sed -e "/^unset i/i\
  77. export TZ=\"\<${timezone}\>${offsethour}\"
  78. " /etc/profile.tmp > /etc/profile

  79.    sed -e "/^set history/i\
  80. setenv TZ \"\<${timezone}\>${offsethour}\"
  81. " /etc/csh.login.tmp > /etc/csh.login

  82. fi

  83. compare_files /etc/profile $stamp
  84. compare_files /etc/csh.login $stamp

  85. rm -f /etc/profile.tmp  /etc/csh.login.tmp

  86. }
復(fù)制代碼

論壇徽章:
0
2 [報告]
發(fā)表于 2011-11-25 09:58 |只看該作者
一般都用 ln -sf /usr/share/zoneinfo/PRC /etc/localtime 吧
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP