Last active
February 21, 2022 10:57
-
-
Save wuftymerguftyguff/c04528417240b532f629ea90ec3adc10 to your computer and use it in GitHub Desktop.
bash script to set standard sap users to not expire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
user_exists(){ id "$1" &>/dev/null; } # silent, it just sets the exit code | |
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | |
DOCFILE="$SCRIPT_DIR/docfile.txt" | |
echo $DOCFILE | |
if [ "$1" == "" ] | |
then | |
echo "SID must be first parameter" | |
exit 1 | |
fi | |
LCDB=$(echo $2 | awk '{print tolower($0)}') | |
if [[ "$2" =~ ^(syb|db2|ora)$ ]] | |
then | |
DB=$2 | |
else | |
echo "Supported DB must be second parameter" | |
exit 1 | |
fi | |
if [ "$3" == "UPDATE" ] | |
then | |
echo User Expiries will be set | |
UPDATE=1 | |
else | |
echo User Expiry Settings will only be displayed | |
fi | |
LCSID=$(echo $1 | awk '{print tolower($0)}') | |
UCSID=$(echo $1 | awk '{print toupper($0)}') | |
SIDADM=${LCSID}adm | |
DBUSER=${LCDB}${LCSID} | |
ABAPSCHEMAUSER="sapr3" | |
JAVASCHEMAUSER=sap${LCSID}db | |
DBUSERLIST="$DBUSER" | |
if [ "$DB" = "ora" ] | |
then | |
DBUSERLIST="$DBUSER oracle" | |
fi | |
if [ "$DB" = "db2" ] | |
then | |
DBUSERLIST="$DBUSERLIST $ABAPSCHEMAUSER $JAVASCHEMAUSER" | |
fi | |
USERLIST="$SIDADM $DBUSERLIST sapadm daaadm" | |
for USER in $USERLIST | |
do | |
if user_exists "$USER" | |
then | |
echo Processing User $USER | |
echo Display User Settings Before any changes | |
chage -l $USER | |
if [ $UPDATE ] | |
then | |
if [ -w $SCRIPT_DIR ] | |
then | |
echo $(date) User $USER on Host $(hostname -f) has user account and password expiry disabled | tee -a $DOCFILE | |
fi | |
chage -m 0 $USER | |
chage -M 99999 $USER | |
chage -E -1 $USER | |
chage -I -1 $USER | |
chage -l $USER | |
fi | |
else | |
echo User $USER does not exist | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment