The following shell script will enable you to make the MongoDB User Management easy without any additional cost/third-party software.

Required software/packages:

Pwp 3.0

RHEL 6+

=============================================================================

#!/bin/bash

## Copy this script to your mongo /bin folder #################################

PWP_HOME=/opt/pwp/3.0

MONGO_HOME=/apps/bin

SCRIPTS=/apps/UMG_Menu/Scripts

HOME=/apps/UMG_Menu/UMG_PWP

LOGS=/apps/UMG_Menu/ScriptLogs

TIMESTAMP=`date +%d-%m-%y_%H:%M:%S`

DATE=`date +%d-%m-%y`

db=admin

local_host=`hostname`

ID=`id -u -n`

echo

echo ” User_Management.sh script is executed by user : $ID”

echo

echo ” Date and Time of Execution : `date`”

echo

read -p “Enter Hostname : ” host

read -p “Enter Port : ” port

var=`grep $host $SCRIPTS/mongodb.ini | grep $port`

if [ -z “$var” ]

then

echo “$host is not in mongodb.ini file – Please provide a valid hostname.” >> $LOGS/UserManagement-$DATE-$TIMESTAMP.log

echo “$host is not in mongodb.ini file – $TIMESTAMP \n” >> $LOGS/UserManagement-$DATE-$TIMESTAMP.log

exit

else

echo “$host is mongodb.ini file – $TIMESTAMP \n” >> $LOGS/UserManagement-$DATE-$TIMESTAMP.log

fi

echo

echo “Hostname and Port number are valid.” >> $LOGS/UserManagement-$DATE-$TIMESTAMP.log

echo

sleep 1

PASWD=`$PWP_HOME/bin/pwpl -a $HOME/access.cf -f $HOME/password.cf $SCRIPTS/GetPw.sh uisabg2 $local_host`

while :

do

clear

echo -e ”

Read More: https://kovidacademy.com/blog/mongodb-user-management-shell-script/

Author's Bio: 

The following shell script will enable you to make the MongoDB User Management easy without any additional cost/third-party software.