When using shell scripts for debugging, the company recently tested the server and often needed to adjust the system time. if one or two servers were better than half and a little bit more, there was a variety of confusions. I was so crazy about these servers. Boss one sentence: all calls are faster than 3 minutes... after the meeting, all the calls will be slowed down for 5 minutes ...... then let's work... when using shell scripts for debugging, the company recently tested the server and often needed to adjust the system time. if one or two servers were better than half and a little bit more, there was a variety of confusions. I was so crazy about these servers. Boss one sentence: all calls are faster than 3 minutes... after the meeting, all the calls will be slowed down for 5 minutes ...... then let's work on various date 01021511 .... you know. so in order to free up productivity, the code is as follows: www.2cto.com #! /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: $3 is none. if [["$3" = "-u"]; then Tcmd = '/usr/bin/rdate '[! -X $ Tcmd] & echo 'rdate not install !! '& Exit 1 "$ Tcmd"-s "$ Tip" fi # Modf if [[-n "$2" & "$1" ='-'| "$1" = '+']; then Func = $1 [["$3" = "-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 the file to the attachment. after downloading the file, give the execution permission first, and then place it to the system path: www.2cto.com [root @ vpn1 scripts] # ls casetup. sh etime. sh [root @ vpn1 scripts] # chmod + x etime. sh [root @ vpn1 scripts] # mv etime. the format of sh/bin/etime usage is as follows: command [+ |-] number [option] The author writes urgently, and the code is not refined. Use with caution: for example, if time synchronization fails, it is not processed, number locations are strictly limited. the usage example is as follows: 1. synchronize with the time server (time.nist.gov)-u, the ninth line of the code, you can modify the specified time server according to your location; if your rdate command is not installed to (/usr/bin/rdate ), the script automatically exits [root @ vpn1 scripts] # date Thu Jan 3 00:13:25 CST 2013 [root @ vpn1 scripts] # etime + 0-u Wed Jan 2 16:13:29 CST 2013 # The first line of output is current Time, when the-u parameter is used, wed Jan 2 16:13:29 CST 2013 # The second row of output is changed to the time [root @ vpn1 scripts] # grep-n "time.nist.gov"/bin/etime 9: tip = 'time .nist.gov '2. the current system time is used for 10 minutes. The default unit is [root @ vpn1 scripts] # etime + 10 Wed Jan 2 16:24:47 CST 2013 Wed Jan 2 16:34:47 CST 2013 3. take the current system time as the standard. the adjustment is slow for 20 minutes, in seconds [root @ vpn1 scripts] # etime-600-s Wed Jan 2 16:36:27 CST 2013 Wed Jan 2 16:26:27 CST 2013 4. take the current world time as the standard and set the speed to 50 minutes, it can only be written in minutes in the unit of [root @ vpn1 scripts] # etime + 50-u Wed Jan 2 16:28:25 CST 2013 Wed Jan 2 17:18:25 CST 2013, give me a compliment (^-^ )..
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.