The company's recent server testing, the need to constantly adjust the system time, one or two is ok half, a little more points, on a variety of entanglements, the author of these several sets of the author is going crazy. Eldest brother: All speed up 3 minutes ... And then they all slow down for 5 minutes. Then we work, all kinds of date 01021511 ... you know. So in order to liberate the productive forces--the code is as follows:
#!/bin/bash #
Author:mos #
Script name:etime.sh
# Date & time:2013-01-02/21:47:58
# version:1.0.1
# Description:
#
#ntpserver
tip= ' time.nist.gov '
# Sync now system time, yes: $3= '-U ' No: $ is none.
if [["$" = "-U"]];then
tcmd= '/usr/bin/rdate '
[!-X $Tcmd] && echo ' rdate not install!! ' && Exit 1
"$Tcmd"-S "$Tip"
fi
# MODF
if [[-N "$" && "$ = =]-' | | "$" = = ' + ']];then
func=$1
[[$] = ' s ']] && num=$2 | | num=$ (($2*60))
ntime= ' Date +%s '
ltime=$ (($Ntime $func$num))
#Date = '/bin/date-d @ ' $Ltime ' 2>/dev/ Null '
#echo $Ltime
res= ' date-d ' 1970-01-01 UTC $Ltime seconds ' +%m%d%h%m%y.%s '
date
date $Res
else
Echo ' first,input + or-; Second,input a number. '
Exit 2
Fi
The author has uploaded to the attachment, after downloading, first give a execute permission, then put to the system path:
[ROOT@VPN1 scripts]# ls
casetup.sh etime.sh
[root@vpn1 scripts]# chmod +x etime.sh
[ROOT@VPN1 scripts ]# MV Etime.sh/bin/etime
The usage format is as follows:
command [+|-] number [option]
I write the urgent, the code is not refined, careful use: For example, time synchronization failed to deal with, number location of the strict restrictions, etc., the use of the following example:
1. Sync with Time server (time.nist.gov)-U, code line nineth, you can modify the specified time server according to your location; If your rdate command is not installed to (/usr/bin/rdate), the script will automatically exit
[ROOT@VPN1 scripts]# Date
Thu 3 00:13:25 CST 2013
[root@vpn1 scripts]# etime + 0-u Wed] 2 16: 13:29 CST 2013 #第一行输出为当前时间, when the-u parameter is used, the time update order is ranked before the modification time
Wed 2 16:13:29 CST 2013 #第二行输出为修改为时间
[ROOT@VPN1 scripts]# grep-n "time.nist.gov"/bin/etime
9:tip= ' time.nist.gov '
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/
2. Take the current system time, adjust the speed 10 minutes, by default in minutes
[ROOT@VPN1 scripts]# etime + 10
Wed 2 16:24:47 CST 2013
Wed 2 16:34:47 CST 2013
3. Take the current system time, slow down 20 minutes, in seconds
[ROOT@VPN1 scripts]# Etime-600-s
Wed 2 16:36:27 CST 2013
Wed 2 16:26:27 CST 2013
4. Take the current world time, adjust the speed 50 minutes, only in minutes
[ROOT@VPN1 scripts]# etime + 50-u
Wed 2 16:28:25 CST 2013
Wed 2 17:18:25 CST 2013
Two additional time servers that are temporarily available:
Time.nist.gov
Rdate.darkorb.net
Time-b.nist.gov
Ntp.openxid.com
It's not easy to write, feel good, give a praise (^-^).
This article from the "Self-Improvement" blog, please be sure to retain this source http://mos1989.blog.51cto.com/4226977/1106272