Sponsored Content
Top Forums Shell Programming and Scripting Shell script to find the run time based on log entries? Post 302467863 by birei on Sunday 31st of October 2010 07:25:56 PM
Old 10-31-2010
Hi,

Try this 'awk' solution:
Code:
$ cat script.awk
BEGIN {
  FS = "[ ,]"; 
} 

NR==1 { 
  datef = $1; 
  timef = $2; 
} 

END { 
  datet = $1; 
  timet = $2;

  split(datef, arrDatef, "-"); 
  split(datet, arrDatet, "-"); 
  split(timef, arrTimef, ":"); 
  split(timet, arrTimet, ":");
  utcDateTimeF = mktime(arrDatef[1] " " arrDatef[2] " " arrDatef[3] " " arrTimef[1] " " arrTimef[2] " " arrTimef[3]);
  utcDateTimeT = mktime(arrDatet[1] " " arrDatet[2] " " arrDatet[3] " " arrTimet[1] " " arrTimet[2] " " arrTimet[3]);
  printf "%s\n", strftime("%H:%M:%S", utcDateTimeT - utcDateTimeF, 1);
}

Code:
$ cat infile
2010-10-30 16:50:38,022 JobRunner.configure Complete
2010-10-30 16:50:38,022 JobRunner.runJob Start
2010-10-30 16:50:38,028 JSRCleaner.cleanJSRs Start
2010-10-30 16:50:38,028 JSRCleaner.cleanJSRs Removing JSRs older than 7 days
2010-10-30 16:50:38,191 JSRCleaner.cleanJSRs Complete
2010-10-30 16:50:38,405 JobRunner.invokeJob Start
2010-10-30 16:50:38,448 AbstractJobInvoker.invokeBatchJob Start
2010-10-30 16:50:38,519 AbstractJobInvoker.invokeBatchJob Complete
2010-10-30 16:50:38,519 JobRunner.invokeJob Complete
2010-10-30 16:50:38,519 JobRunner.monitorJob Start
2010-10-30 17:42:46,494 JobRunner.monitorJob Complete
2010-10-30 17:42:46,536 JobRunner.runJob Complete
2010-10-30 17:42:46,536 JobRunner.processMain Complete : Return Code 0

Code:
$ awk -f script.awk infile
00:52:08

Regards,
Birei
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Find files based on time

Hi, Whats the command for finding files older then 20mins. This has to be part of the find command as it will be part of a cleanup script. thanks Budrito (4 Replies)
Discussion started by: budrito
4 Replies

2. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

3. Shell Programming and Scripting

How to find the time taken for a script to run?

I have just written a Csh script and i want to find out how long does the script take to complete executing. Is there any codes which i can put into my script to capture its run time ? (9 Replies)
Discussion started by: Raynon
9 Replies

4. Shell Programming and Scripting

Connect Oracle using shell script at run time

Hi all, I am a newbie.....am jus trying to connect to oracle thro a script, but not thro giving the username/password@server_name directly like `$ORACLE_HOME/bin/sqlplus username/password@server_name In the above line, once it is connected to Oracle, it shud ask me the username and password... (4 Replies)
Discussion started by: kritibalu
4 Replies

5. Shell Programming and Scripting

Picking contents value of file at run time based on variable values

HI, I have to write a unix script and need your help. in my application where I have to invoke this script a varialble is there where the value comes in a variable . for example variable can be var=ABC like this there will be any type of value in the vcariable. there is a unix directory... (2 Replies)
Discussion started by: manish8484
2 Replies

6. Shell Programming and Scripting

How to give password at run time in a shell script?

hi, how can i pass a password automatically when a shell script is running. i have shell script(runscript.sh) which call another shell script inside it as a different user. runscript.sh contains su - nemo -c "/bin/main_script.sh" but when i execute "runscript.sh" it try to run... (7 Replies)
Discussion started by: Little
7 Replies

7. Shell Programming and Scripting

Run a shell script on all 15 servers at the same time?

We have 15 servers. Hostnames for these 15 servers are stored in a text files and loop through each server to connect to the remote server and run a command, but this loop process runs the command one after another. However, the requirement is to run the same command on all 15 servers at the same... (10 Replies)
Discussion started by: laknar
10 Replies

8. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

9. UNIX for Beginners Questions & Answers

Shell Script to run in given time

Hi All, Would like to write a Script which will run between 11am to 3 pm and send the results to output.txt. Please suggest. (2 Replies)
Discussion started by: vasuvv
2 Replies

10. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies
File::Slurp::Unicode(3pm)				User Contributed Perl Documentation				 File::Slurp::Unicode(3pm)

NAME
File::Slurp::Unicode - Reading/Writing of Complete Files with Character Encoding Support SYNOPSIS
use File::Slurp::Unicode; my $text = read_file('filename', encoding => 'utf8'); my @lines = read_file('filename'); # utf8 is assumed if no encoding. write_file('filename', { encoding => 'utf16' }, @lines); # same as File::Slurp::write_file (ie. no encoding): write_file('filename', { encoding => 'binary' }, @lines); use File::Slurp::Unicode qw(slurp); my $text = slurp('filename', encoding => 'latin1'); DESCRIPTION
This module wraps File::Slurp and adds character encoding support through the "encoding" parameter. It exports the same functions which take all the same parameters as File::Slurp. Please see the File::Slurp documentation for basic usage; only the differences are described from here on out. read_file Pass in an argument called "encoding" to change the file encoding. If no argument is passed in, UTF-8 encoding is assumed. The special encoding 'binary' is interpreted to mean that there should be no decoding done to the data after reading it. This is pretty much the same as calling "File::Slurp::read_file()" directly. This option is here only to make code which needs to read both binary and text files look uniform. write_file Pass in an argument called "encoding" to change the file encoding. If no argument is passed in and no wide characters are present in the output data, then no conversion will be done. If there are wide characters in the output data then UTF-8 encoding is assumed. The special encoding 'binary' is interpreted to mean that there should be no encoding done to the data before writing. If you pass a wide string (a string with Perl's internal 'utf8 bit' set) to "write_file" and set the encoding to 'binary' it will die with an appropriate message. This is pretty much the same as calling "File::Slurp::write_file()" directly. This option is here only to make code which needs write both binary and text files look uniform. SEE ALSO
File::Slurp BUGS
None known. Contact author or file a bug report on CPAN if you find any. COPYRIGHT
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2010 David Caldwell AUTHOR
David Caldwell <david@porkrind.org> <http://porkrind.org/> PROJECT HOME
<http://github.com/caldwell/File-Slurp-Unicode> perl v5.10.1 2010-10-28 File::Slurp::Unicode(3pm)
All times are GMT -4. The time now is 12:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy