Skip to content

Commit

Permalink
add check-users.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 17, 2025
1 parent bbbaa31 commit 469fce7
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions local-app/bin/check-users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

cleanup()
{
local rstatus=$?
if [[ ! -z $TMPDIR ]] && [[ -e $TMPDIR ]]
then
rm -rf $TMPDIR
fi
exit $rstatus
}
trap cleanup EXIT

VERSION="1.1.0"
THIS=$(basename $0)
export TMPDIR=$(/bin/mktemp -d /tmp/check-users.XXXXXXXX) || (echo "#* error making TMPDIR" && exit 1)
#OUTFILE="$(basename $THIS .sh).$(date +%s).txt"
OUTFILE="$TMPDIR/$(basename $THIS .sh).$(date +%s).txt"

echo "is_separated,has_mail username employeeType loginDisabled mail"

IS_SEPARATED=""
NO_MAIL=""

if [ -z "$1" ]
then
FILE=users.csv
else
FILE=$1
fi

for f in $(awk -F, 'NR>1 {print $1}' users.csv)
do
/apps/terraform/bin/ldapsearch cn=$f dn employeeType mail loginDisabled > $OUTFILE
error=0
dn_exists=$(grep -c ^dn $OUTFILE)
mail=$(grep ^mail $OUTFILE|awk '{print $2}')
if [ -z "$mail" ]
then
has_mail=0
NO_MAIL+=" $f"
error=$(( error + 1 ))
mail="(none)"
else
has_mail=1
fi
et=$(grep ^employee $OUTFILE|awk '{print $2}')

logindisabled=$(grep ^loginDisabled $OUTFILE|awk '{print $2}')
if [[ $(echo $et | grep -ci /separated) == 1 ]]
then
is_separated=1
IS_SEPARATED+=" $f"
error=$(( error + 1 ))
else
is_separated=0
fi

if [[ $dn_exists == 0 ]]
then
et="not-present/no-jbid"
logindisabled="REMOVED"
else
if [ -z "$et" ]
then
et="(not-person)"
fi
fi

if [ $error != 0 ]
then
echo "$is_separated,$has_mail $f $et $logindisabled $mail"
fi
done

0 comments on commit 469fce7

Please sign in to comment.