【初始化-系统时间】init_datetime.sh

#!/bin/bash
# 
# 2014/07/15

#timezone
ec_timezone() {
    echo "[*] timezone: Asia/Shanghai"
    mv -f /etc/localtime /etc/localtime.old
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    mv -f /etc/sysconfig/clock /etc/sysconfig/clock.old
    echo ‘ZONE="Asia/Shanghai"‘ >/etc/sysconfig/clock 
    echo "[*] done!"
}

#NTP服务

ec_ntpd() {
    echo "[*] update ntp config file..."
    cp /etc/ntp.conf /etc/ntp.conf.default
    cat <<_NTP >/etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify
restrict -6 default kod nomodify
restrict 127.0.0.1 
restrict -6 ::1

server cn.pool.ntp.org
server time.windows.com
server time.nist.gov
server time-nw.nist.gov
server time-a.nist.gov
server time-b.nist.gov
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
_NTP
    echo "[*] done!"
}

usage() {
    cat <<_USAGE

Usage:
    $0 s
    $0 c domain_or_ip 

_USAGE
}

case $1 in
    s)
        ec_timezone
        ec_ntpd
        service ntpd stop
        echo "[*] ntpdate cn.pool.ntp.org..."
        /usr/sbin/ntpdate cn.pool.ntp.org
        service ntpd start
        chkconfig ntpd on
        chkconfig --list |grep ntpd
        ;;
    c)
        ec_timezone
        service ntpd stop
        echo "ntpdate $2..."
        ntpdate $2
        chkconfig ntpd off
        chkconfig --list |grep ntpd
        echo "[*] edit crontab: */20 * * * * /usr/sbin/ntpdate $2 >/dev/null &"
        ;;
    *)
        usage
        ;;
esac
时间: 2024-08-26 03:12:24

【初始化-系统时间】init_datetime.sh的相关文章

【初始化-系统时间】init_profile.sh

#!/bin/bash #  # 2014/10/20 #profile,增加到最后 cat <<_PROFILE >>/etc/profile alias ls='ls --color=tty' alias ll='ls -l --color=tty' alias l.='ls -d .* --color=tty' alias vi='vim' alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias grep='grep 

Linux系统时间与RTC时间【转】

http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3637782 Linux的RTC驱动相对还是比较简单的,可以将它作为一个普通的字符型设备,或者一个misc设备,也可以是一个平台设备,这都没有关系,主要还是对rtc_ops这个文件操作结构体中的成员填充,这里主要涉及到两个方面比较重要: 1. 在Linux中有硬件时钟与系统时钟等两种时钟.硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟.系统时钟则是指kernel中的

[javascript]获取系统时间函数

var oDate=new Date(); //初始化系统时间函数 alert(oDate.getHours()); //获取时 alert(oDate.getMinutes()); //获取分 alert(oDate.getSeconds()); //获取秒

利用Saltstack的States初始化系统

今天和大家介绍一下如何运用State初始化系统吧 States是satlstack中的配置语言  安装软件包.管理配置文件都需要编写一些states sls文件   states sls使用YAML语法 查看所有states列表[[email protected]    pillar]#    salt 'onde1' sys.list_state_modules    (node1是被管理节点的ID) 查看states模块功能[[email protected]    pillar]#    

实例365(2)---------调用系统api修改系统时间

一:截图 二:代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace SetDate { public partial cl

关于时间的操作(JavaScript版)——年月日三级联动(默认显示系统时间)

这个功能是大学时自己使用纯JavaScript写的,没有借助Jquery,呵呵呵,看起来有点繁琐,可是在当时依稀的记得功能实现后自己好好的高兴一把了呢,从现在来看那时候的自己是多么的幼稚.多么的无知: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>年月日三级联动(默认显示系统时间)</title> <

【原】定时器与系统时间

问题:--------------------------------------------------------------------------------用户反馈一些定时活动提前开启或者延后开启1) 登录服务器,查看时间确实慢了或者快了.总之是有几台服务器时间不准确了.2) 查看代码是使用的ScheduledExecutorService.scheduleAtFixedRate,Java的API,不至于这里存在Bug3) 查看log4j日志输出发现:    12点的定时活动,之前的[

Linux驱动中获取系统时间

最近在做VoIP方面的驱动,总共有16个FXS口和FXO口依次初始化,耗用的时间较多.准备将其改为多线程,首先需要确定哪个环节消耗的时间多,这就需要获取系统时间. #include <linux/time.h> /*头文件*/ struct timeval time_now; unsigned long int time_num;//获取的时间 do_gettimeofday(&time_now); time_num = time_now.tv_sec*1000+time_now.tv

MFC显示系统时间

准备工作: 1.在视图中右击->类向导->消息->找到消息WM_TIMER,同事右侧会出现消息的响应函数OnTimer,双击OnTimer 一.标题栏显示系统时间 1.在BOOL XXXDlg::OnInitDialog()函数中添加定时器SetTimer(1,1000,NULL);//第一个参数是定时器ID,你随意定,但是如果不能喝其他定时器的ID重复,第二个参数是时间(ms)就是每隔多长时间执行一次,第三个参数一般为NULL,为NULL是表示使用OnTimer为响应函数,当然你也可以