k8s多pod查询日志脚本

1.创建脚本文件
vi log.sh
2.脚本内容
#!/bin/bash
a=$(kubectl -n videocloud get pods | grep $1)
services=$(echo $a | tr ";" "\n")
for s in $services
do
if [[ $s =~ $1 ]]
then
echo $s
#kubectl -n videocloud exec -it $s -- cat /code/logs/$2 | grep 'redis'
#kubectl -n capacity exec -it $s -- sed -n '/2020-09-30 08:30:00/,/2020-09-29 08:40:30/p' /code/logs/$2 | grep '33082200001327853286'
kubectl -n capacity exec -it $s -- cat /code/logs/$2 | grep '33108100001310773347'
else
continue
fi
done
3.赋权
chmod +x -R *
4.运行
./log.sh vch-cnt-adapt-provider info.2022-04-18.log

posted @ 2022-04-18 14:11  逐梦寻欢  阅读(397)  评论(0编辑  收藏  举报