问题
I am trying to write a script that will have the following information:
4824597 11:26 /home/customer1/ITAM.xml
.
.
.
.
4824597 14:08 /home/customer46/ecds/dropoff/ITAM.xml
I have another file that will log the same information
4824597 11:28 /home/customer1/ITAM.xml
.
.
.
.
4824597 14:11 /home/customer46/ecds/dropoff/ITAM.xml
I want see how long it takes to receive files. To do this I want to subtract the timestamp of all the files logged in the log, and subtract them from their initial timestamp in the first log file.
I am new to scripting and am struggling to make this work. I am trying:
#!/bin/bash
time=$11:48:30
day=$2012-10-12
time2=$13:13:48
t=$(date -d "day time" +%s)
t1=$(date -d "day time2" +%s)
diff=$(expr $t1 - $t)
echo $diff
So far no luck. Any help would be greatly appreciated.
回答1:
Try something like this:
awk '{
sub(/:/," ",$2);
t1=mktime(strftime("%Y %m %d")" "$2" 00");
getline < "input2.txt";
sub(/:/," ",$2);
t2=mktime(strftime("%Y %m %d")" "$2" 00");
print $3": "t2-t1" s"
}' input1.txt
来源:https://stackoverflow.com/questions/17241982/bash-script-to-take-the-timestamp-of-a-logged-files-and-subtract-it-from-the-tim