Shell script to slow down system time (used when testing the server) _linux Shell

Source: Internet
Author: User

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:

Copy Code code 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:

Copy Code code as follows:

[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:
Copy Code code 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

Copy Code code as follows:

[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 sorted 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 '

2. Take the current system time , adjust the speed 10 minutes, by default in minutes

Copy Code code as follows:

[ROOT@VPN1 scripts]# etime + 10
Wed 2 16:24:47 CST 2013
Wed 2 16:34:47 CST 2013

3. The current system time is subject to, slow down for 20 minutes, in seconds
Copy Code code as follows:

[ROOT@VPN1 scripts]# Etime-600-s
Wed 2 16:36:27 CST 2013
Wed 2 16:26:27 CST 2013

4. Taking the current world time as the subject, speed 50 minutes, only in minutes
Copy Code code as follows:

[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:
Copy Code code as follows:

Time.nist.gov
Rdate.darkorb.net
Time-b.nist.gov
Ntp.openxid.com

It's not easy to write, feel good, give a praise (^-^).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.