在 bash 中显示数据网格

在 bash 中显示数据网格

想获得关于如何在 bash 中最好地做到这一点的意见,谢谢

对于 x 台服务器,每台服务器都有自己的复制协议列表及其状态。可以轻松运行一些命令并获取此数据,例如;

获取服务器,输出;

dc1-server1 dc1-server2 dc2-server1 dc2-server2 dc3...

对于dc1-server1,获取协议,输出;

dc2-server1
dc3-server1
dc4-server1

对于dc1-server1,获取协议状态码,输出;

0
0
18

因此,对于该服务器,输出将是基于“获取服务器”列表的几列,其中每个服务器下的每个“副本:状态”

这可能会被搞砸,但是类似的东西;

dc1-server1      dc1-server2      dc2-server1
dc2-server1: 0   dc2-server2: 0   dc1-server1: 0  ...
dc3-server1: 0   dc3-server2: 18  dc3-server1: 13 ...
dc4-server1: 18  dc4-server2: 0   dc4-server1: 0  ...

类似这样的东西(尽管这不起作用);

#!/bin/bash

. ~/.ldap-config
DOMAIN=$(domainname)
ROWSTOT=0

for SERVER in $MASTER $REPLICAS ; do
   ${SERVER}REPLICAS=$(ipa-replica-manage -p $(cat ~/.dsp) list -v $SERVER.$DOMAIN | grep ': replica' | sed 's/: replica//')
   ROWS=$(echo "${SERVER}REPLICAS" | wc -l)
   [ "$ROWS" -gt "$ROWSTOT" ] && ROWSTOT=$ROWS
   ${SERVER}STATUS=$(ipa-replica-manage -p $(cat ~/.dsp) list -v $SERVER.$DOMAIN | grep 'status: Error (' | sed -e 's/.*status: Error (//' -e 's/).*//')
done

for (( C=1; C<=$ROWSTOT; C++ )) ; do
   for SERVER in $MASTER $REPLICAS ; do
      #echo -n "${SERVER}REPLICAS[$C]: ${SERVER}STATUS[$C]"
      printf "%-28s" "${SERVER}REPLICAS[$C]: ${SERVER}STATUS[$C]"
   done
   echo
done

ipa-replica-manage 的输出示例;

# ipa-replica-manage -p $(cat ~/.dsp) list -v $(hostname)
dc1-server2.domain: replica
  last update status: Error (0) Replica acquired successfully: Incremental update succeeded
  last update ended: 2021-04-08 12:13:05+00:00
dc4-server2.domain: replica
  last update status: Error (0) Replica acquired successfully: Incremental update succeeded
  last update ended: 2021-04-08 12:13:05+00:00
dc3-server1.domain: replica
  last update status: Error (0) Replica acquired successfully: Incremental update succeeded
  last update ended: 2021-04-08 12:13:05+00:00
dc2-server1.domain: replica
  last update status: Error (0) Replica acquired successfully: Incremental update succeeded
  last update ended: 2021-04-08 12:13:05+00:00

.ldap-config 具有本地环境/集群设置(有多个具有不同服务器名称/数量的集群),但这里使用的唯一行是,例如;

MASTER=dc1-server1
REPLICAS="dc1-server2 dc2-server1 dc2-server2 dc3...  "

相关内容