bash脚本采取的一个记录的文件的时间戳和从另一个日志文件的时间戳减去它 [英] Bash Script to take the timestamp of a logged files and subtract it from the timestamp of another log file

查看:95
本文介绍了bash脚本采取的一个记录的文件的时间戳和从另一个日志文件的时间戳减去它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本,将具有下列信息:

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

到目前为止,没有运气。任何帮助将大大AP preciated。

So far no luck. Any help would be greatly appreciated.

推荐答案

尝试是这样的:

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

这篇关于bash脚本采取的一个记录的文件的时间戳和从另一个日志文件的时间戳减去它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆