and the rest of it...
This commit is contained in:
156
ldif/genUser.sh
Normal file
156
ldif/genUser.sh
Normal file
@@ -0,0 +1,156 @@
|
||||
#!/bin/bash
|
||||
#A script to generate a LDIF file of random users and associated organizational units
|
||||
#supports emitting ldif files for: Active Directory, eDirectory, OpenLDAP
|
||||
|
||||
################################################################################
|
||||
#Change these variables as needed #
|
||||
################################################################################
|
||||
#Number of users to generate
|
||||
#Valid range is from 1 to 10,000
|
||||
NUMUSERS="11"
|
||||
|
||||
#Type of directory server to generate ldif for
|
||||
#Valid types (case sensitive):
|
||||
#OPENLDAP
|
||||
#ACTIVEDIRECTORY
|
||||
#EDIRECTORY
|
||||
DIRSERVERTYPE="OPENLDAP"
|
||||
|
||||
################################################################################
|
||||
#!!!!!!!!!!!!!!!!!!!!DO NOT CHANGE ANYTHING BEYOND THIS LINE!!!!!!!!!!!!!!!!!!!#
|
||||
################################################################################
|
||||
|
||||
|
||||
|
||||
USERCOUNTER="1"
|
||||
NAMESOURCEFILE="./names.txt"
|
||||
OUSOURCEFILE="./ou.txt"
|
||||
OUTPUTFILE="bulkUserLoad-$DIRSERVERTYPE-$(date +%m%d%Y).ldif"
|
||||
|
||||
function ldifEmit-OpenLDAP()
|
||||
#Code to emit an OpenLDAP compliant ldif
|
||||
#Bits and bobs sourced from:
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
{
|
||||
|
||||
cat<<OpenLDAP >>$OUTPUTFILE
|
||||
$FIRSTNAME
|
||||
$LASTNAME
|
||||
$OU
|
||||
OpenLDAP
|
||||
|
||||
}
|
||||
|
||||
|
||||
function ldifEmit-ActiveDirectory()
|
||||
#Code to emit an Active Directory compliant ldif
|
||||
#Bits and bobs sourced from:
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
{
|
||||
|
||||
echo "Emitting ActiveDirectory ldif..."
|
||||
|
||||
cat<<ActiveDirectory >>$OUTPUTFILE
|
||||
$FIRSTNAME
|
||||
$LASTNAME $OU
|
||||
ActiveDirectory
|
||||
ActiveDirectory
|
||||
|
||||
}
|
||||
|
||||
|
||||
function ldifEmit-eDirectory()
|
||||
#Code to emit an eDirectory compliant ldif
|
||||
#Bits and bobs sourced from:
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
{
|
||||
|
||||
echo "Emitting eDirectory ldif..."
|
||||
|
||||
cat<<eDirectory >>$OUTPUTFILE
|
||||
$FIRSTNAME $LASTNAME $OU
|
||||
eDirectory
|
||||
eDirectory
|
||||
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
#Range / value check on user supplied variables
|
||||
|
||||
if [ $NUMUSERS -lt 1 -o $NUMUSERS -gt 50000 ]; then
|
||||
echo "Number of users not correctly specified"
|
||||
echo "Valid range is from 1 to 10,000"
|
||||
echo "Exiting now...."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Number of user range is ok..."
|
||||
|
||||
if [ -z $NUMUSERS ]; then
|
||||
echo "Number of users not specified."
|
||||
echo "A value of 1 to 10,000 must be specififed."
|
||||
echo "Exiting now...."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z $DIRSERVERTYPE ]; then
|
||||
echo "Directory server type not specified."
|
||||
echo "Exiting now...."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f $OUTPUTFILE
|
||||
|
||||
cat <<RUNNING
|
||||
Generating LDIF file:
|
||||
Formatted for $DIRSERVERTYPE with a user count of $NUMUSERS.
|
||||
Output will be at $OUTPUTFILE
|
||||
Please wait...
|
||||
RUNNING
|
||||
|
||||
while [ $USERCOUNTER -le $NUMUSERS ]
|
||||
do
|
||||
|
||||
#Get a random first/last name
|
||||
NAMELINECOUNT=$(cat $NAMESOURCEFILE | wc -l)
|
||||
NAMERANDNUM1=$(cat /proc/sys/kernel/random/uuid | cut -c1-4 | od -d | head -1 | cut -d' ' -f2)
|
||||
NAMERANDNUM2=$(cat /proc/sys/kernel/random/uuid | cut -c1-4 | od -d | head -1 | cut -d' ' -f2)
|
||||
NAME1=$(expr $NAMERANDNUM1 % $NAMELINECOUNT + 1)
|
||||
NAME2=$(expr $NAMERANDNUM2 % $NAMELINECOUNT + 1)
|
||||
FIRSTNAME=$(head -$NAME1 $NAMESOURCEFILE | tail -1)
|
||||
LASTNAME=$(head -$NAME2 $NAMESOURCEFILE | tail -1)
|
||||
|
||||
#Get a random OU
|
||||
OULINECOUNT=$(cat $OUSOURCEFILE | wc -l)
|
||||
OURANDNUM=$(cat /proc/sys/kernel/random/uuid | cut -c1-4 | od -d | head -1 | cut -d' ' -f2)
|
||||
OUNUM=$(expr $OURANDNUM % $OULINECOUNT + 1)
|
||||
OU=$(head -$OUNUM $OUSOURCEFILE | tail -1)
|
||||
|
||||
|
||||
#Emit ldif
|
||||
if [ $DIRSERVERTYPE = "OPENLDAP" ]; then
|
||||
ldifEmit-OpenLDAP $FIRSTNAME $LASTNAME $OU
|
||||
elif [ $DIRSERVERTYPE = "ACTIVEDIRECTORY" ]; then
|
||||
ldifEmit-ActiveDirectory $FIRSTNAME $LASTNAME $OU
|
||||
elif [ $DIRSERVERTYPE = "EDIRECTORY" ]; then
|
||||
ldifEmit-eDirectory $FIRSTNAME $LASTNAME $OU
|
||||
fi
|
||||
|
||||
#Increment counter
|
||||
USERCOUNTER=$(( $USERCOUNTER + 1 ))
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
#Kick it all off
|
||||
main
|
Reference in New Issue
Block a user