Last active
December 20, 2015 16:19
-
-
Save jamesmartin/6160689 to your computer and use it in GitHub Desktop.
Calculate the duration (in seconds) of a process based on its log file entries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| timestamp() { | |
| date -j -f "%Y-%m-%d%H:%M:%S" $* +%s | |
| } | |
| extract_time_field(){ | |
| echo $* | awk '{print $1$2}' | awk -F',' '{print $1}' | |
| } | |
| for logfile in `ls *.log`; do | |
| starttime=$(extract_time_field $(cat $logfile | head -n1)) | |
| endtime=$(extract_time_field $(cat $logfile | tail -n1)) | |
| difference=$(expr $(timestamp $endtime) - $(timestamp $starttime)) | |
| echo "$logfile: Duration (seconds): $difference" | |
| done |
Author
Author
Example output:
foo.log: Duration (seconds): 79
bar.log: Duration (seconds): 4
baz.log: Duration (seconds): 33
qux.log: Duration (seconds): 74
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The input log files are expected to be in the following format (only the date/time stamps are important):
Put all the log files in the same directory as the script and run it.
Milliseconds are discarded.