time - How to get sar command value in 24 hour format (from 00:00:00 to 23:59:59) in Linux? -


I want to generate a file containing the cpu usage log in 24 hour format ( 00:00:00 to 23:59:59 ). I am using the sar command but it gives time in AM or PM format which is not necessary.

Sample:

  12:01:01 AM All 1.33 0.00 1.06 0.24 0.00 97.37 12:02:01 All 1.30 0.00 1.02 0.04 0.00 97.64  

Expected Result:

  00:01:01 All 1.33 0.00 1.06 0.24 0.00 97.37 00:02:01 All 1.30 0.00 1.02 0.04 0.00 97.64  

sir is a so-called localized program The output format is controlled by lc_ * environment variable. The variable LC_TIME is responsible for the production of time data. (See Man Locale ).

It seems that you are using a system where LC_TIME is set to en_US - a locale 12hours AM / PM By using the format (or LC_TIME was left empty, it would prompt you to use the default locale). You will need to use a local setting which is using 24 hour format. You can specify it at the command line:

  LC_TIME = en_UK.utf8 sar  

Output:

  Linux 3.13.0-44- Generic (Desktop 1) 01/22/15 _x86_64_ (4 CPU) 00:00:01 CPU% User% Good% System% iowait% Stolen% Waste 00:02:01 All 2,26,0,00 0,41 0,71 0,00 96,63 00:04:01 All 2,68,0,00,072,46 , 00,00 96,13 ...  

Note! If the locale en_UK.uft8 is not available on your system, then you need to use it:

  sudo locale-gen en_UK.utf8  < / Pre> 

Or you use POSIX or C :

  LC_TIME = 'POSIX' Sir LC_TIME = 'C' Can  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -