diff --git a/local-app/bin/check-users.sh b/local-app/bin/check-users.sh new file mode 100755 index 00000000..dff16851 --- /dev/null +++ b/local-app/bin/check-users.sh @@ -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