add possibility to run db-statement on connectdb

This commit is contained in:
Jakobus Schürz 2023-11-16 15:40:29 +01:00
parent 797e4da5d1
commit 255fbf0907

View file

@ -1179,18 +1179,31 @@ function connectdb () {
getdbcreds_cnf $2 getdbcreds_cnf $2
;; ;;
*) *)
echo "wrong argument" echo "wrong argument" >&2
return 1 return 1
;; ;;
esac esac
cat << EOF cat << EOF >&2
connect to ${DB_HOST}:${DB_PORT}/${DB_NAME} connect to ${DB_HOST}:${DB_PORT}/${DB_NAME}
with user: ${DB_USER} with user: ${DB_USER}
and passwd: ${DB_PWD} and passwd: ${DB_PWD:+********}
EOF EOF
if [ $# -gt 0 ]
then
case $1 in
-c)
shift
PGPASSWORD=$DB_PWD psql -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME -c "$@"
;;
*)
PGPASSWORD=$DB_PWD psql -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME $@
;;
esac
else
PGPASSWORD=$DB_PWD psql -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME PGPASSWORD=$DB_PWD psql -h $DB_HOST -p $DB_PORT -U $DB_USER $DB_NAME
fi
} }