Update LDIF User info based on Test User Certs ID's


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Update LDIF User info based on Test User Certs ID's
# 1  
Old 07-13-2010
Update LDIF User info based on Test User Certs ID's

Hi I need help..........

I have an Sun One Directory server LDIF file with 5000 user entries, I need to change the data to match Test ID's, so I can run a perf test.

I'm way out of my league as I have not done any scripting for 10 years.

There are four entries for each user in the file that I need to update with the uid from a list in another file.

Code:
dn: uid=xxxzzze000,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze000.xxxzzze000@uk.company.com
uid: xxxzzze000

The real users are not wholly sequential........

They range from

Code:
xxxzzze000 - xxxzzze999
xxxzzzf000 - xxxzzzf999
xxxzzzh000 - xxxzzzh999
xxxzzzi000 - xxxzzzi999
xxxzzzj000 - xxxzzzj999


The Test users are
Code:
xxxzzze1000 -xxxzzze5000

Has anyone got a script for changing entries in a file based on input from another file?

Thx

---------- Post updated at 05:13 PM ---------- Previous update was at 02:09 PM ----------

I think I nead something like this.....


Code:
#!/bin/bash
read oldval
read newval
while read line
do
{
sed 's/'$oldval'/'$newval'/g' $line >$line".new"
}
done<list.txt

If I am correct this would take a list input from a file; read the old value and replace with the new value in the same file

so if the file had in it -
Code:
xxxzzze000 xxxzzze1000
xxxzzze001 xxxzzze1001
xxxzzze002 xxxzzze1002

The script should replace
Code:
dn: uid=xxxzzze000,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze000.xxxzzze000@uk.company.com
uid: xxxzzze000

dn: uid=xxxzzze001,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze001.xxxzzze001@uk.company.com
uid: xxxzzze001

dn: uid=xxxzzze002,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze002.xxxzzze002@uk.company.com
uid: xxxzzze002

with the following
Code:
dn: uid=xxxzzze1000,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze1000.xxxzzze1000@uk.company.com
uid: xxxzzze1000

dn: uid=xxxzzze1001,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze1001.xxxzzze1001@uk.company.com
uid: xxxzzze1001

dn: uid=xxxzzze1002,l=emea,ou=internal,ou=people,dc=company,dc=com
mail: xxxzzze1002.xxxzzze1002@uk.company.com
uid: xxxzzze1002

Can anyone verfiy?

The file is in Standard LDIF format so there are a block of entries per user

Code:
dn: uid=xxxzzze000,l=emea,ou=internal,ou=people,dc=company,dc=com
objectClass: inetorgperson
objectClass: person
objectClass: internalperson
objectClass: organizationalperson
objectClass: person
objectClass: top
objectClass: service
c: GB
cn: Alasdair J 
employeeNumber: 000300
givenName: Alasdair
mail: xxxzzze000.xxxzzze000@uk.company.com
preferredLanguage: en
countryCode: UK
employeeType: Test
jobTitle: INTNST
los: ABAS
sn: J
uid: xxxzzze000
userPassword::

The second file is just a list of id's in sequential order. So I need to finds the id in the LDIF and change it based on the new ID's in all the correct places in the LDIF for 5000 users.



Moderator's Comments:
Mod Comment Please use code tags. Thank you.

Last edited by Macdaddy99; 07-14-2010 at 12:15 PM.. Reason: Code tags
# 2  
Old 07-14-2010
how is the input file formatted? You're on the right track.. but i think your read oldval/newval statements aren't going to do much.

Are the two files formatted kind of similarly? or no?
# 3  
Old 07-14-2010
Hi, I suspect this should be enough to make the desired changes if you just want to change the three digits to four, the first being a 1:
Code:
sed 's/xxxzzz./&1/g infile > infile.new

# 4  
Old 07-14-2010
Wood for the trees.........

Quote:
Originally Posted by Scrutinizer
Hi, I suspect this should be enough to make the desired changes if you just want to change the three digits to four, the first being a 1:
Code:
sed 's/xxxzzz./&1/g infile > infile.new



Thanks your right its basically 1 sed command...........

Smilie

Last edited by Macdaddy99; 07-14-2010 at 12:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Sudo and edit other user's info.

i did a mistake. :( user1 ]$ vi ~/.bashrc sudo su - user2 now , whenever I try to login to user1 , it will login to user2. How can I resolve this ? :rolleyes: N.B -- I do not have root access. -- I dont know password of user2 -- this is a virtual machine. (1 Reply)
Discussion started by: linuxadmin
1 Replies

2. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

3. Linux

Could not get info for user -- wbinfo

Hi Experts, I'm not able to get the info of user's from wbinfo. But I'm able to join the user in domain(net rpc join -U username....). I have deleted the *.tdb file under /var/lib/smaba and set winbind cache time = 40 and restarted the winbind, Still it not works.. And not able to... (0 Replies)
Discussion started by: eeegopikannan
0 Replies

4. AIX

User attributes not update in user file

Hi Admins, I am running IAX 5.3 I have created a user with attributes maxage et. The user entry i can see in /etc/security/user file with only one attribute admin=false. how to update the user attributes like maxage etc. Regards Pavan (1 Reply)
Discussion started by: newaix
1 Replies

5. Shell Programming and Scripting

Prompt user for info

Please forgive this newbie question. I have a need to create a script that asks a user for information. Something like: What is the name: $NAME_TYPED_HERE Is $NAME_TYPED_HERE Correct ? YES (NO would go back to -What is the Name-) mkdir then goes on behind the scene and makes folder called... (1 Reply)
Discussion started by: crowman
1 Replies

6. UNIX for Dummies Questions & Answers

User Info

How could I get the details about a user logged in a Unix system? ( WHat tasks did he perform or if he had changed any file or not)? Please answer my question. (1 Reply)
Discussion started by: s_dhar
1 Replies

7. UNIX for Dummies Questions & Answers

getting user info on a file

I know this is prob a simple question but anyway here goes. I want to find out the owner of a certain file. I also want to find out what permissions that owner has. Is their any command that is similair to file in that it can tell men this specfic information about a file the way file tells you... (1 Reply)
Discussion started by: Quesa
1 Replies

8. Filesystems, Disks and Memory

? on xferring user info from one sys to another

I've been setting up a duplicate system to replace an ailing ultra 2, same os version, same file & directory structure, same databases, now I just wanted to doublecheck that for user info, to copy over exact user login info, i need to copy the etc/passwd, etc/group and etc/shadow files. THis will... (6 Replies)
Discussion started by: kymberm
6 Replies

9. UNIX for Advanced & Expert Users

User log in info

Hi, I am using SunOS and HP-UX. I am trying to removed user that has not been using the system for a period of time. Is there anyway to find out how long since the last time the user logged on. I know there is command "last" that read from the file /etc/wtmp that hold some of information. ... (1 Reply)
Discussion started by: vtran4270
1 Replies
Login or Register to Ask a Question