0

would like to get an opinion on how best to do this in bash, thank you

for x number of servers, each has it's own list of replication agreements and their status.. it's easy to run a few commands and get this data, ex;

get servers, output;

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

for dc1-server1, get agreements, output;

dc2-server1
dc3-server1
dc4-server1

for dc1-server1, get agreement status codes, output;

0
0
18

so output would be several columns based on the 'get servers' list with each 'replica: status' under each server, for that server

this may get munged, but something like;

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  ...

something vaguely like this (tho this doesn't work);

#!/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

example output from 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 has local env/cluster settings (there are several clusters w/different server names/quantities), but the only lines used here are, ex;

MASTER=dc1-server1
REPLICAS="dc1-server2 dc2-server1 dc2-server2 dc3...  "
8
  • 1
    Please add more details on how you receive the data. Are these command outputs? Are they input files? Commented Apr 7, 2021 at 15:07
  • the commands are a bit specific to the env.. for the servers list (get servers), these are in a source'd config file, which has different names/quantity depending on the env/cluster, ex; SERVERS="dc1-server1 dc2-server2 ..." Commented Apr 7, 2021 at 16:06
  • Then for each server, parse a (ipa) command to get the replication agreements server names (get agreements) and also parse the command to get replication status for those servers (get agreement status codes). Data all comes from; 'ipa-replica-manage list -v $SERVER' Commented Apr 7, 2021 at 16:08
  • Issue really, the data comes in as various columns to be assigned to vars during the data collection phase, but then has to be printed onscreen a row at a time for all the various servers.. kind of in a grid format. Commented Apr 7, 2021 at 16:08
  • 2
    Please take our short tour to learn how this site is supposed to work. Relevant information should be in the question body, not in comments. Now you should edit the question, put the new information there, finally delete the comments. Welcome to the site. Commented Apr 7, 2021 at 16:21

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.