請問一下,我想截取下表 Kubernetes 的 EXPIRES 或 RESIDUAL TIME 來提示到期日,及計算到期日並發告警。因為會受到
像 RESIDUAL TIME、CERTIFICATE、May 04, 2032 12:32 UTC 這類有空格,所以沒法抓完整,不知這樣表格型的怎麼截
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf May 04, 2032 12:32 UTC 9y no
apiserver May 04, 2032 12:32 UTC 9y ca no
apiserver-etcd-client May 04, 2032 12:32 UTC 9y etcd-ca no
apiserver-kubelet-client May 04, 2032 12:32 UTC 9y ca no
controller-manager.conf May 04, 2032 12:32 UTC 9y no
etcd-healthcheck-client May 04, 2032 12:32 UTC 9y etcd-ca no
etcd-peer May 04, 2032 12:32 UTC 9y etcd-ca no
etcd-server May 04, 2032 12:32 UTC 9y etcd-ca no
front-proxy-client May 04, 2032 12:32 UTC 9y front-proxy-ca no
scheduler.conf May 04, 2032 12:32 UTC 9y no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca Apr 27, 2031 23:37 UTC 8y no
etcd-ca Apr 27, 2031 23:37 UTC 8y no
front-proxy-ca Apr 27, 2031 23:37 UTC 8y no
使用 cut -c 配合位置來截。比如你想截取 EXPIRES 欄位,就是下
cut -c 28-50 /tmp/Kubernetes.log
(假設你上面的內容在 /tmp/Kubernetes.log 裡)
就可以抓到 EXPIRES 欄位的值了。同理,你要抓 CERTIFICATE AUTHORITY 的值,就是下
cut -c 69-90 /tmp/Kubernetes.log
要兩欄一起抓就是
cut -c 28-50,69-90 /tmp/Kubernetes.log
感謝,知道怎麼用了
kubeadm certs check-expiration |cut -c 1-39,28-49| awk 'NR>3'
ERTIFICATE EXPIRES
admin.conf May 04, 2032 12:32 UTC
apiserver May 04, 2032 12:32 UTC
apiserver-etcd-client May 04, 2032 12:32 UTC
apiserver-kubelet-client May 04, 2032 12:32 UTC
controller-manager.conf May 04, 2032 12:32 UTC
etcd-healthcheck-client May 04, 2032 12:32 UTC
etcd-peer May 04, 2032 12:32 UTC
etcd-server May 04, 2032 12:32 UTC
front-proxy-client May 04, 2032 12:32 UTC
scheduler.conf May 04, 2032 12:32 UTC
CERTIFICATE AUTHORITY EXPIRES
ca Apr 27, 2031 23:37 UTC
etcd-ca Apr 27, 2031 23:37 UTC
front-proxy-ca Apr 27, 2031 23:37 UTC