天天看點

設定時區,時間,日期的腳本

#!/bin/bash

:<<COMMENT

Author:huangyandong

Date:11/13/11 release 1.0

Web:http://huangyandong.blog.51cto.com

RunAs:root

COMMENT

PS3="選擇操作:"

select doing in "設定時區" "設定日期" "設定時間" "顯示目前時間和日期" "退出" 

do

if [ x$doing == "x設定時區" ];then

zone=$(tzselect)

echo "你要設定的時區為$zone,确定(y)"

read isdo

case $isdo in

    y|Y)  cp -v /usr/share/zoneinfo/${zone} /etc/localtime ;;

esac

fi

if [ x$doing == "x設定日期" ];then

read -p "輸入要設定的日期(YYYY-MM-DD)" sdate

echo "你要設定的日期為$sdate,确定(y)"

    y|Y) date +%D -s "$sdate" ;;

if [ x$doing == "x設定時間" ];then

read -p "輸入要設定的時間(HH:MM:SS)" stime

read -p "是否使用UTC時間,是(y)" sutc 

case $sutc in

    y|Y) msg="使用UTC時間";utc='-u';;

echo "你要$msg設定的時間為$stime,确定(y)"

    y|Y) date +%T -s "$stime" $utc ;;

if [ x$doing == "x顯示目前時間和日期" ];then

date

if [ x$doing == "x退出" ];then

exit 0;

done