Linux simple time and processing time interval.

Recently want to know their time-consuming to deploy a script, read something about noon easiest Linux a function of time

I deal with here is very simple, just enough of it. 

Process. 

1. Get the current time:

= TIME1 `date` in the previous 
or 
TIME1 = $ (DATE) 
If the acquired quite nice time format may be used:
TIME1 + DATE ="% D%% Y-M-% H:% M:% S "` then verify function correct echo $ time1 to Note 1: variable name behind time1 immediately followed by an equal sign can not have spaces, otherwise it will be interpreted as a command of the equal sign can not have spaces. Note 2: You can use backticks or performed two ways brackets processing command.

You can also use
= `date +% s` may acquire unix timestamp timestamp1, so can be time-consuming calculation simple.

2. Add two shell command each time acquiring and acquired unix timestamp at the beginning and end of deployment scripts.

3. In the last increase in script execution of simple processing

= `expr $ timestamp2 interval1 - $ timestampe1` 

calculates the duration 

can then use the command echo echo 

echo " The start time of the $ time1 this time $ time2 end of this time-consuming $ interval1 seconds " 

note subtraction when the subtraction operation both ends of the operation must have spaces, otherwise there will be problems.

4. In fact, the processing can also be provided, and the shell is a function of time Time Format

But I feel this most simple. 

Simply record it. 

 

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11584165.html