shell script help for users

Hello guys, I would appreciate if someone can help me for this task:

I have a large txt file that contains lots of user ids in different format. I need to run this against a database output ldif file and print to a file whether they exist or not. And if they exist then I need to print their information from the ldif file. I appreciate in advance if anyone can assist.

Thanks again

It would help if you told us the format of the files.

Oh, and the output of "uname -a".

Hi - thanks for the input:

THe user file looks like ( a chunk of it ):

060606ab
12345678910
110maryland
123thebestfather
1superman1
22221111333_1234567

And the ldif file ( a section of it ) looks like:

dn: uid=MYFILE1,ou=someou,o=test.com
21tCGX2RdpxnkaJU0mI/BC0jdaBBbUt8gjnRxAhMU2
authpassword;orclsomepwd: {ABC}a2F4=
businesscategory: SomeCategory
createtimestamp: 2007070911234z
creatorsname: cn=someload
modifiersname: cn=someoad
modifytimestamp: 20070709181203z
objectclass: top
objectclass: someUser
orclguid: ABCDFF4AD107
orclnormdn: uid=myid1,ou=someconsumer,o=vz.com
pwdchangedtime: 20070709181203z
uid: MYFILE1
userpassword: ABCDRFGEmBXrHCKZa2F4=
canswer: Hello
cinkid: MYFILE1
cquestion: What is my mother's maiden name
cusergroup: somecustomer
cuserstatus: 0

Actually if a uid in the txt file exist in the ldif file, I want to print dn, cquestion, and userstatus

server information: sun os 5.9
it has perl version 5.6.1

any script/program such as shell script, perl script using awk/sed/etc would help me a lot, I appreciate ...

You could do something like

#!/bin/sh

while read N M
do
     case "$N" in
     uid:  )
         echo "$M"
         ;;
     * )
         ;;
     esac
done <ldif

so save that as one script, say, called ldif-uid.sh

then have another which looks for exact lines

#!/bin/sh

M="$1"

while read N
do
    if test "$N" = "$M"
    then
          exit 0
    fi
done

exit 1;

then chain them together

./ldif-uid.sh | exact.sh some-uid

and that would tell you if that user exists

then do another while loops round the whole list of users

#!/bin/sh

while read N
do
     ./ldif-uid.sh | ./exact.sh "$N"
     if test "$?" = "0"
     then
             echo user "$N" exists
     else
             echo user "$N" does not exist
     fi
done <users

let me work on it, I will post a msg as soon as possible...I appreciate for your help.

when I combined 2 scripts recevied error below...can you please tell me what am I doing wrong ? I used for N v2.txt and M test.ldif ...

./uid.sh | uid2.sh next-uid
./uid.sh: v2.txt: is not an identifier
uid2.sh: test.ldif=next-uid: not found
uid2.sh: v2.txt: is not an identifier

thnx much again

I suggest you post *exactly* what you have put in your scripts and use the [ CODE ] [ / CODE ] markers.

Hi - please see below ... so far could not make it working :frowning:
Thanks for the help.

###########################################
#!/bin/sh
# uid.sh

while read v2.txt test.ldif
do
case "$v2.txt" in
uid: )
echo "$test.ldif"
;;
* )
;;
esac
done < test.ldif

######################################

#!/bin/sh
# uid2.sh

test.ldif="$1"

while read v2.txt
do
if test "$v2.txt" = "$test.ldif"
then
exit 0
fi
done

exit 1;

#####################################

./uid.sh | uid2.sh next-uid

#####################################

#!/bin/sh
# uid3.sh

while read v2.txt
do
./uid.sh | ./uid2.sh "$v2.txt"
if test "$?" = "0"
then
echo user "$v2.txt" exists
else
echo user "$v2.txt" does not exist
fi
done <users

####################################

Hm,

the construct

while read VAR1 VAR2 VAR3 .... VARN
do
    ..... $VAR1 etc ....
done <FILE

expects FILE to be the filename you want to read
and VAR1 VAR2 etc to be variable names to be used inside the do/done.

The idea of splitting these up into individual scripts is you can test them individually, so running the first script should just print a list of valid userids from the ldap dump.

mmmm if i understood correctly, VAR1, VAR2 .. etc are uid's ....but there are so many of them in a txt file. Is there a way I can get the txt running against the ldif to check all uids ? Thanks much...