pdadmin script help needed

Hello all,

I need to create a report for the list of users and related groups present in my ldap directory.

I need a script which does the following and give out a final script as specified. Any help is appreciated.

1)pdadmin -a sec_master -p <passwd> group show-members <groupname> >> groupmembers.txt
2)select each entry in groupmembers.txt and do the following commands in order:
2a)pdadmin -a sec_master -p <passwd> user show-groups <each entry in groupmembers.txt> >> user&group.txt
2b)pdadmin -a sec_master -p <passwd> user show <each entry in groupmembers.txt> |grep cn= , sn= >> user&group.txt (cn=firstname sn =lastname)
so finally the user&group.txt should contain something like this:
userid's groups firstname lastname

in order to help, we'll need sample output from each of the pdadmin commands.

1)pdadmin -a sec_master -p <passwd> group show-members <groupname>

output: user1
user2
user3 ....
2a)pdadmin -a sec_master -p <passwd> user show-groups <user1>
group1
group2
group3...
2b) pdadmin -a sec_master -p <passwd> user show <each entry in groupmembers.txt> |grep cn= , sn=
LDAP DN: cn=user1ou=people,o=uhg,c=us
LDAP CN: first
LDAP SN: user
Description:
Is SecUser: Yes
Is GSO user: No
Account valid: Yes
Password valid: Yes

ksh code:

pdadmin -a sec_master -p <passwd> group show-members <groupname> |
while read user ; do

  groups=$( pdadmin -a sec_master -p <passwd> user show-groups $user )

  pdadmin -a sec_master -p <passwd> user show $user |
    awk '/LDAP CN:/{ print $3; }' |
    read first

  pdadmin -a sec_master -p <passwd> user show $user |
    awk '/LDAP SN:/{ print $3; }' |
    read last

  echo $user $groups $first $last

done |
  tee this_script.log

thanks a lot i will try it out

getting this error when i run it
Unrecognized file test: -a at ./audit.pl line 5.

what's the 'audit.pl'? I don't see any mention of the perl module in the posted solution.
and what's the "test" file? Don't call your script 'test' - there's a shell builtin utility called 'test' - call your script something else (preferably with the .sh extension).

Also post your script using BB codes.

i changed it to .sh extension but get this error

Code Output:
./audit.sh: syntax error at line 6: `groups=$' unexpected

#!/bin/ksh

pdadmin -a sec_master -p <passwd> group show-members <groupname> |
while read user ; do

  groups=$( pdadmin -a sec_master -p <passwd> user show-groups $user )

  pdadmin -a sec_master -p <passwd> user show $user |
    awk '/LDAP CN:/{ print $3; }' |
    read first

  pdadmin -a sec_master -p <passwd> user show $user |
    awk '/LDAP SN:/{ print $3; }' |
    read last

  echo $user $groups $first $last

done |
  tee this_script.log

i tried to run this got the below error:

Error Code:
./audit.sh[3]: syntax error at line 4 : `|' unexpected

have you replaced all the <passwd> <groupname> stuff
with actual values?

It works now thanks a lot.