Skip to content

Commit

Permalink
add script for checking groups
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Sep 16, 2025
1 parent 1251062 commit a1a755c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions local-app/bin/check-groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

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

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

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

ts=$(date +%s)
c=0
for f in $(awk -F, 'NR>1 {print $1}' $FILE)
do
c=$(( c + 1 ))
/apps/terraform/bin/ldapsearch -LLL cn=$f member |grep ^member: | grep -v cn=p- | sed -e 's/,.*$//' -e 's/^.*=//' > $TMPDIR/group_$f
echo "* group $f members $(wc -l $TMPDIR/group_$f | awk '{print $1}')"
done
cat $TMPDIR/group_* | sort > $TMPDIR/members
sort -u $TMPDIR/members > $TMPDIR/members.csv
echo "n_groups username"
uniq -c $TMPDIR/members | sort -nr|awk '{print $1,$2}'
m=$(wc -l $TMPDIR/members.csv|awk '{print $1}')

te=$(date +%s)
tx=$(( te - ts ))
echo ""
echo "summary: groups $c members $m elapsed $tx"

echo ""
check-users.sh $TMPDIR/members.csv

0 comments on commit a1a755c

Please sign in to comment.