본문 바로가기

Cloud/Linux

터미널에서 명령어 timestamp를 찍고 싶을 때 - moreutils

테스트를 진행하다보면 10초, 20초 단위로 옵션을 변경하여 결과를 볼 때가 많다. 이 때 time이나 쉘 스크립트를 이용해서 측정할 수 있겠지만 두 개 이상의 명령어를 수행할 때에는 비교의 어려움이 있다. 그럴 때에는 현재 시간에 기반하여 흐름을 파악하는 것이 편한데 그 때 사용하는 패키지를 소개한다.

https://joeyh.name/code/moreutils/

 

moreutils

moreutils is a growing collection of the unix tools that nobody thought to write long ago when unix was young. It began when I blogged: I'm a fan of the unix tools philosophy, but I sometimes wonder if there's much room for new tools to be added to that to

joeyh.name

apt install -y moreutils

여러 도구가 있는데 ts를 사용하면 된다.

root@c1:~# kubectl get pods -n kube-system -w | ts '[%Y-%m-%d %H:%M:%S]'
[2020-05-06 14:55:26] NAME                                      READY   STATUS    RESTARTS   AGE
[2020-05-06 14:55:26] calico-kube-controllers-59fc8847c-76fgn   1/1     Running   0          8d
[2020-05-06 14:55:26] calico-node-7jqn7                         1/1     Running   5          31d
[2020-05-06 14:55:26] calico-node-dtz7t                         1/1     Running   2          12d
[2020-05-06 14:55:26] calico-node-qb2xx                         1/1     Running   1          8d
[2020-05-06 14:55:26] coredns-5c98db65d4-4kbdq                  1/1     Running   6          8d
[2020-05-06 14:55:26] coredns-5c98db65d4-dqmw8                  1/1     Running   6          8d
[2020-05-06 14:55:26] etcd-c1                                   1/1     Running   5          90d
[2020-05-06 14:55:26] etcd-c1                                   1/1     Running   6          7d23h
[2020-05-06 14:55:26] etcd-c1                                   1/1     Running   19         12d
[2020-05-06 14:55:26] kube-apiserver-c1                         1/1     Running   0          55m
[2020-05-06 14:55:26] kube-apiserver-c1                         1/1     Running   0          52m
[2020-05-06 14:55:26] kube-apiserver-c1                         1/1     Running   1          50m
[2020-05-06 14:55:26] kube-controller-manager-c1                1/1     Running   16         90d
[2020-05-06 14:55:26] kube-controller-manager-c1                1/1     Running   17         7d23h
[2020-05-06 14:55:26] kube-controller-manager-c1                1/1     Running   29         12d
[2020-05-06 14:55:26] kube-proxy-9kbd8                          1/1     Running   1          7d23h
[2020-05-06 14:55:26] kube-proxy-jkpns                          1/1     Running   1          90d
[2020-05-06 14:55:26] kube-proxy-mjvr2                          1/1     Running   2          12d
[2020-05-06 14:55:26] kube-scheduler-c1                         1/1     Running   15         90d
[2020-05-06 14:55:26] kube-scheduler-c1                         1/1     Running   19         7d23h
[2020-05-06 14:55:26] kube-scheduler-c1                         1/1     Running   32         12d

[2020-05-06 14:55:52] kube-scheduler-c1                         1/1     Terminating   19         7d23h
[2020-05-06 14:55:53] kube-scheduler-c1                         1/1     Terminating   19         7d23h
[2020-05-06 14:55:53] kube-scheduler-c1                         1/1     Terminating   19         7d23h
[2020-05-06 14:55:53] kube-scheduler-c1                         0/1     Pending       0          5s
[2020-05-06 14:55:54] kube-scheduler-c1                         0/1     Terminating   0          6s
[2020-05-06 14:55:54] kube-scheduler-c1                         0/1     Terminating   0          6s

이런 식으로 사용할 수 있다.

https://unix.stackexchange.com/questions/26728/prepending-a-timestamp-to-each-line-of-output-from-a-command

 

Prepending a timestamp to each line of output from a command

I wish to prepend a timestamp to each line of output from a command. For example: foo bar baz would become [2011-12-13 12:20:38] foo [2011-12-13 12:21:32] bar [2011-12-13 12:22:20] baz ...where...

unix.stackexchange.com

 

'Cloud > Linux' 카테고리의 다른 글

DNS 공부 1  (0) 2021.03.03
IPTABLES  (0) 2021.03.03
네임스페이스 입력 받아서 백업  (0) 2020.12.18
ssh - Permission denied (publickey,gssapi-keyex,gssapi-with-mic).  (0) 2020.10.07
apt install error (/var/lib/dpkg/lock-frontend)  (0) 2020.09.15