# ts

# 介紹

# 情境描述

在 crontab 會執行一些排程的任務,像是定期 reindex 資料庫的 index。另外,我會 pipe 執行結果到檔案裡面,不過這些執行結果沒有 timestamp 所以會不知道是何時執行的,這樣要除錯可能就會比較困難,所以找了一下解決方案,StackOverflow 上這篇文章 shell - Bash: Append command output and timestamp to file - Stack Overflow (opens new window) 有一些解法,有些太複雜了,有看到一個 ts 的 command line 程式,就試著用一下,效果不錯,介紹給大家。

# 安裝

Debian 可以用 apt 安裝

sudo apt-get install moreutils

# 基本使用

使用方式很簡單,只要 pipe 到 ts 在 output 的開頭就會加上 timestamp 了

root:~ % psql -c 'REINDEX INDEX foo;'
REINDEX

root:~ % psql -c 'REINDEX INDEX foo;' | ts
 3月 12 11:24:09 REINDEX

參考資料

Last Updated: 2021-11-26 16:02:26
贊助商連結
    贊助商連結
    (adsbygoogle = window.adsbygoogle || []).push({});