From 690811ccfb445248e9cd06479c4c5a88fe1ecae9 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 30 Jan 2018 17:45:15 +0100 Subject: [PATCH] Add -U parameter to provide user to use on master host --- check_pg_streaming_replication | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/check_pg_streaming_replication b/check_pg_streaming_replication index 1385182..264ec0d 100755 --- a/check_pg_streaming_replication +++ b/check_pg_streaming_replication @@ -20,6 +20,7 @@ # PG_USER=postgres +PG_MASTER_USER="" PSQL_BIN=/usr/bin/psql PG_MAIN=/var/lib/postgresql/9.1/main if [ -f /etc/debian_version ] @@ -48,6 +49,7 @@ Usage : $0 [-d] [-h] [options] $PG_MAIN) -r recovery_conf Specify Postgres recovery configuration file path (Default : [PG_MAIN]/$RECOVERY_CONF_FILENAME) + -U pg_master_user Specify Postgres user to use on master (Default : user from recovery.conf file) -p pg_port Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT) -D dbname Specify DB name on Postgres master/slave to connect on (Default : PG_USER) -d Debug mode @@ -56,7 +58,7 @@ EOF exit 0 } -while getopts "hu:b:m:r:p:D:d" OPTION +while getopts "hu:b:m:r:U:p:D:d" OPTION do case $OPTION in u) @@ -71,6 +73,9 @@ do r) RECOVERY_CONF=$OPTARG ;; + U) + PG_MASTER_USER=$OPTARG + ;; p) PG_DEFAULT_PORT=$OPTARG ;; @@ -188,13 +193,19 @@ then debug "Master port : $M_PORT" fi - M_USER=$( echo "$MASTER_CONN_INFOS"|sed 's/^.*user= *\([^ ]*\) *.*$/\1/' ) - if [ ! -n "$M_USER" ] + if [ -n "$PG_MASTER_USER" ] then - debug "Master user not specify, use default : $PG_USER" - M_USER=$PG_USER + debug "Master user provided by command-line, use it : $PG_MASTER_USER" + M_USER="$PG_MASTER_USER" else - debug "Master user : $M_USER" + M_USER=$( echo "$MASTER_CONN_INFOS"|sed 's/^.*user= *\([^ ]*\) *.*$/\1/' ) + if [ ! -n "$M_USER" ] + then + debug "Master user not specify, use default : $PG_USER" + M_USER=$PG_USER + else + debug "Master user : $M_USER" + fi fi # Get current xlog file from master