0
我有一個備份,在午夜開始,並在完成時發送電子郵件。我想檢查基礎上的運行時間:BASH:減去日期以獲得運行時間
日誌格式(在/ var /日誌/ maillog中):
Oct 4 08:23:35 test postfix/smtp[5351]: C5BBB2115C: to=<[email protected]>, relay=aspmx.l.google.com[74.125.206.26]:25, delay=30213, delays=30212/0.06/0.22/0.46, dsn=2.0.0, status=sent (250 2.0.0 OK 1412407415 q20si4382781wie.36 - gsmtp)
我不知道我怎樣才能從午夜減去完成時間以收到運行(如果有幫助,它不一定是awk)?
例子:
# awk '/[email protected]/{ printf ("%s%s%s\n", "Completed at: ", $3, " Runtime: ") }' /var/log/maillog
Completed at: 17:45:52 Runtime: 17h:45m:52s
Completed at: 08:56:00 Runtime: 08h:56m:00s
Completed at: 07:18:32 Runtime: 07h:18m:32s
Completed at: 05:53:23 Runtime: 05h:53m:23s
Completed at: 06:03:24 Runtime: 06h:03m:24s
Completed at: 08:50:51 Runtime: 08h:50m:51s
Completed at: 08:23:35 Runtime: 08h:23m:35s
將兩者都轉換爲UNIX紀元時間(自1-1-1970年以來的秒數)並相減。 GNU日期會爲你做轉換,然後bash的內置數學就足夠了。 – 2014-10-04 18:49:04