Novell Home

The Magic of GSAR

Novell Cool Solutions: Tip

Digg This - Slashdot This

Posted: 4 Aug 2004
 

Here's a clever solution to a common problem, sent in by Cool Solutions reader Marcel Tempelman. You can use the GSAR program to perform replacements on a large scale and automate lots of different tasks. Enjoy!

The Problem

At our school, most of the students have a unique ID, but we also needed to have a certain amount of generic student accounts. For example, for a course they use user accounts 600 to 750. Because we're getting rid of certain trees, and these accounts weren't in the main tree, I had to find a comfy way to recreate them.

The Solution

With the help of the magnificent Search and Replace tool GSAR (found at http://home.online.no/~tjaberg/, GPL-ed software), I was able to create a batch script that generates, with the help of a template, an LDIF file with all needed user accounts. Once the LDIFGEN batch script is done, you only have to fire up ICE and import them into your tree.

How it Works

1) Create a LDIF-file of a user account with the needed eDirectory properties (export an user, clean it up if necessary).

2) Replace the username in the LDIF file with XXX. Save the file as XXX.LDIF and save it in the same directory as LDIFGEN.BAT and GSAR.EXE. This is your LDIF Template.

3) Open a Command prompt and go to the directory that contains LDIFGEN.BAT.

Now you have several options for running the command.

Example 1: LDIFGEN 200 300

This will generate a LDIF-file for the useraccounts 200 to 300.

Example 2: LDIFGEN 200 300 /p student-

The /p option puts an prefix in the useraccountname, in this case a LDIF-file will be generated for the accounts Student-200 to Student-300.

This can be handy for creating classroom accounts. If I want to create 22 accounts for classroom B156, I would enter:

LDIFGEN 1 22 /p B156-

I would get a LDIF-file for the account B156-1, B156-2 etc. (You could also extend the script.) All in all, it's a pretty simple system and highly customizable. After the import standard things need to be done with creating the home directories, etc.

Example: XXX.LDIF

dn: cn=xxx,ou=99,ou=USERS,ou=OW,o=Acme
changetype: add
nIMSParentObject: cn=OW-Netmail-Parent,ou=Parent Objects,o=Internet Services
uid: xxx
givenName: xxx
fullName: PLC-deelnemer account xxx
sn: xxx
passwordUniqueRequired: TRUE
passwordRequired: TRUE
passwordMinimumLength: 8
passwordExpirationInterval: 15724800
passwordAllowChange: TRUE
userpassword: verander
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
objectClass: ndsLoginProperties
loginScript: END
loginMaximumSimultaneous: 1
loginGraceRemaining: 3
loginGraceLimit: 3
loginAllowedTimeMap:: AAAAAAAAAPz//wMAAPz//wMAAPz//wMAAPz//wMAAPz//wMAAAAAAAAA
ou: Cluster Economie
l: Energieweg
ndsHomeDirectory: cn=OW-ALG-01_VOL1,ou=OW,o=Acme#0#\Home\99\xxx
securityEquals: cn=ENE-PLC-Best,ou=USERS,ou=OW,o=Acme
groupMembership: cn=ENE-PLC-Best,ou=USERS,ou=OW,o=Acme
description: xxx account. Each participant gets a numerical account from xxx to 750. These accounts circulate during the school year.
cn: xxx

dn: cn=ENE-PLC-Best,ou=USERS,ou=OW,o=Acme
changetype: modify
add: member
member: cn=xxx,ou=99,ou=USERS,ou=OW,o=Acme
Example: LDIFGEN.BAT

@echo off
set pref=leeg
set count=1
if %1!==! goto routine
if %2!==! goto routine
if %1 GTR %2 goto routine

:prefixcheck
if /I %3!==! goto noprefix
if /I %3 == /p goto prefix
if /I not %3 == /p goto routine

:noprefix
set pref=0
set number=%1
gsar -sxxx -r%number% -f xxx.ldif final.ldif >NIL
goto nextstep

:prefix
set pref=1
if %4!==! goto routine
set number=%1
gsar -sxxx -r%4%number% -f xxx.ldif final.ldif >NIL
goto nextstep

:question
if /I %number% LSS %2 goto nextstep
if /I %number% GEQ %2 goto results

:nextstep
CLS
set /a number+=1
set /a count+=1
Echo.
Echo Creating LDIF file
Echo Created %count%
if /I %pref% == 0 gsar -sxxx -r%number% -f xxx.ldif temp.ldif >NIL
if /I %pref% == 1 gsar -sxxx -r%4%number% -f xxx.ldif temp.ldif >NIL
copy temp.ldif+final.ldif fintemp.ldif /Y >NIL
copy fintemp.ldif final.ldif /Y >NIL
goto question

:test
Echo /p textstuff

:routine
Echo.
Echo LDIFGen
Echo.
Echo Use  : ldifgen {startingnumber} {lastnumber} /p {PREFIX}
Echo.
Echo Example    : Ldifgen 800 900
Echo    : generates an LDIF file for user accounts 800 to 900
Echo    :
Echo    : Ldifgen 800 900 /p testuser-
Echo    : generates a LDIF file for user accounts
testuser-800
Echo     to testuser-900
Echo.
Echo    Be sure that {beginning number} is lower than the {end number}
Echo.

goto end-script

:results
Echo LDIF file created with %count% user accounts. For import use:

Final.ldif

:end-script


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell