I have a log file and I need to make some calculations between two jobs to find time difference.
In my log file I am supposed to calculate time between the jobs incoming request
and candidate list sent for
which took 2 seconds in the log below as an example;
2019-08-23 00:05:27 42303: incoming request: 1dd5.073f.5d5f0397 (156074 bytes)
2019-08-23 00:05:27 42303: store file: /papillon1/vrf/rq/1dd5.073f.5d5f0397.rq, len: 156074
2019-08-23 00:05:27 42303: registering process 42605 left to finish it's work
2019-08-23 00:05:27 42605: making search request for: 1dd5.073f.5d5f0397
2019-08-23 00:05:27 42605: 1dd5.073f.5d5f0397 is request for search by fingers
2019-08-23 00:05:27 42605: portions: 156
2019-08-23 00:05:27 42605: request pattern version 8
2019-08-23 00:05:27 42605: fingers mask: 1111111111; quality mask: 3011031110
2019-08-23 00:05:27 42605: saving request file: /papillon1/vrf/rqm/1dd5.073f.5d5f0397.rqm~
2019-08-23 00:05:27 42605: renaming request file: /papillon1/vrf/rqm/1dd5.073f.5d5f0397.rqm~ -
> /papillon1/vrf/rqm/1dd5.073f.5d5f0397.rqm
2019-08-23 00:05:27 42605: request file saved /papillon1/vrf/rqm/1dd5.073f.5d5f0397.rqm
2019-08-23 00:05:27 42605: request is in queue: 1dd5.073f.5d5f0397
2019-08-23 00:05:27 42605: request 1dd5.073f.5d5f0397 registering time: 663 msec
2019-08-23 00:05:28 42303: waiting for 42605 to be finished
2019-08-23 00:05:28 42303: 42605 finished; waiting time: 0 ms
2019-08-23 00:05:29 43188: candidate list for 1dd5.073f.5d5f0397; 2 records
2019-08-23 00:05:29 43188: candidate list file size: 381
2019-08-23 00:05:29 43188: candidate list sent for: 1dd5.073f.5d5f0397
so I created a script that reads all the maps in the log file and make calculations between 2 jobs for that map. In the log above 1dd5.073f.5d5f0397
is one map as an example.
Also here is my full script;
#!/bin/bash
for i in $(grep 'incoming request:' a8.svrf.ear | sed 's/^.*: //' | awk -F'[ ]' '{print $1}')
do
var0=$i
TIME1=$(grep 'incoming request:' a8.svrf.ear | awk -F'[ ]' '{print $2}')
TIME2=$(grep 'candidate list sent for:' a8.svrf.ear | grep "$var0" | awk -F'[ ]' '{print $2}')
SEC1=$(date +%s -d "${TIME1}")
SEC2=$(date +%s -d "${TIME2}")
DIFFSEC=$(expr "${SEC2}" - "${SEC1}")
echo Map "${var0}" >> /home/st/anil/test.txt
echo Start "${TIME1}" >> /home/st/anil/test.txt
echo Finish "${TIME2}" >> /home/st/anil/test.txt
echo Took "${DIFFSEC}" seconds >> /home/st/anil/test.txt
echo Took $(date +%H:%M:%S -ud @"${DIFFSEC}") >>/home/st/anil/test.txt
echo =========================================================================
done
In my code I basically tried to get all maps with a for loop and for each map I tried to get time for 2 jobs and find the time difference but my output is something unexpected ;
=========================================================================
...
34\n11:33:42\n11:33:42\n11:33:47’
expr: non-integer argument
date: invalid date ‘@’
=========================================================================
date: invalid date ‘00:01:37\n00:05:27\n00:09:49\n00:11:18\n00:12:02\n00:12:28\n00:12:52\n00:13:24\n00:15:10\n00:16:
...
Also in the output txt file I face something like this for every map;
Map 1dd5.0721.5d5f02b1
Start 00:01:37
00:05:27
00:09:49
00:11:18
00:12:02
00:12:28
00:12:52
00:13:24
00:15:10
00:16:05
00:22:36
00:23:14
00:23:44
00:24:15
00:25:26
00:26:07
00:27:04
00:27:34
...
Finish
Took seconds
Took
=========================================================================
I would be glad if you guys show my mistake. Thank you
"${TIME1}"
and"${TIME2}"
are quoted? otherwise errors such as this might occur if one of yourgrep
s matches none or more than one line. (If they are properly quoted and grep matches more than one line, it will still be an error of course, though probably an "invalid date").bash -x
output into your question so that its formatting is preservedgrep
s. You need to re-think the whole approach so as to guarantee thatdate -d
receives a single valid date string.date -d
and I tested my greps as a single command on shell and all of them gave me what I need