script to update gecos in passwd file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to update gecos in passwd file
# 1  
Old 03-05-2008
script to update gecos in passwd file

Hello,
I need to add information in the gecos of each login in the passwd file. I have expect installed. I thought about using expect to to read a file with the login names and the gecos information and then execute the command passwd with the -f option. The other option would be to read the passwd file and split the login at the first letter (ie: jyoung > j young) and then placing that in the gecos part. This is on AIX 5.2. Does anyone have a script that would do this or someting similar that I could modify. Thank you.
# 2  
Old 03-05-2008
Ok, I have create a Perl script that I believe will do the job. Could some of you take a look at it and let me know if you see any problems? Also if I replace the passwd file in etc with the output from this what types of problems might I have.
Code:
#!/usr/bin/perl
open (users,"</law1/passuser") or die ("Cannot open passuser");
while (<users>) {
      ($uname,$x,$uid,$gid,$gecos,$home,$shell) = split ':', $_;
      if (length($gecos)==0)
         {
          $first_l=substr($uname,0,1);
          $gecos_l=length($uname)-1;
          $second_l=substr($uname,1,$gecos_l);
          $full_n=$first_l . " " . $second_l;
         }
      else
         {$full_n=$gecos;}
       print "$uname:$x:$uid:$gid:$full_n:$home:$shell";
}

I still have some tweaking to do, but I thought before I go any farther I would have you take a look. When I run the script I will redirect the output to a file. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script need to do update xml file

<avp name="CC-Request-Type" value="1"> </avp> <avp name="CC-Request-Number" value="0"> </avp> <avp name="Subscription-Id"> <avp name="Subscription-Id-Type" value="0"></avp> <avp name="Subscription-Id-Data" value="4081234567"></avp> </avp> <avp... (5 Replies)
Discussion started by: gstar
5 Replies

2. Emergency UNIX and Linux Support

Email ids from gecos

I would like to extract only the email ids from the gecos of each user id. I have to get the email ids of all the users on the server like this. Can someone please assist me with the command/script? (15 Replies)
Discussion started by: ggayathri
15 Replies

3. Shell Programming and Scripting

Script to update data in a file

Hi, I need a script to update a line in a file with a file name everytime it runs. For example below are two files each files contains two rows(say 4&5) which needs to be updated with a file name abc.param xyz.param Now below are two filenames which have date and time appended to... (1 Reply)
Discussion started by: sv0081493
1 Replies

4. Emergency UNIX and Linux Support

Script for deleting orphan ids & unknown gecos

The AIX servers that I am working on have been identified as having orphaned user ids & improper gecos for some user ids. Can someone help me with a script to delete the user ids if the orphaned ids are provided in a text file. The home directory set up for the user ids happen to be the... (1 Reply)
Discussion started by: ggayathri
1 Replies

5. Shell Programming and Scripting

How to update an entry of another file in a Shell script?

Hi all, Say I have a shell script called update_password.sh - in this script I want to perform a task to update a specified entry of another file (e.g. users.passpords) update_password.sh #!/bin/bash -e PW_FILE_DIR="${A_DIR}/.../..." PW_FILE="users.passwords" I want to update the... (2 Replies)
Discussion started by: isaacniu
2 Replies

6. Shell Programming and Scripting

perl script to update a xml file

Hi experts, I have a set of xml files in folder which has the below field. <mm:sessionID>157.235.206.12900397BE4:A</mm:sessionID>, I need to update this field regularly with new session id, which I have it from a login file. Can anyone tell me how to add a new value in <mm:sessionID>... (3 Replies)
Discussion started by: amvarma77
3 Replies

7. Shell Programming and Scripting

call a passwd file to a script multiple times

Hello everybody, I have a requirement in my script.. When i'am executing a script, it'll ask a passwd of some service account.. I need to pass it to the script through a zipped file when it asks for it. The script can be executed by more people many number times. So for securty purpose, it... (1 Reply)
Discussion started by: raghu.iv85
1 Replies

8. Shell Programming and Scripting

sed script to manipulate the /etc/passwd file

Hi. Can anybody help me with a script to extract usernames, shell and home_directory from the /etc/passwd file. I am stuck (2 Replies)
Discussion started by: Pauline mugisha
2 Replies

9. Shell Programming and Scripting

update file contents using shell script

Hi, I am having a file which contains as below Names(aaaa ,bbbb ,cccc ,dddd) now i want the file to be updated with new value 'eeee' as below Names(aaaa ,bbbb ,cccc ,dddd ,eeee) Is there a way to script this ? Thanks, (5 Replies)
Discussion started by: drams
5 Replies

10. Shell Programming and Scripting

How to update passwd

I created a new user for my SUN machine for eg iachasta 1.) added the entry in the /etc/passwd file with corresponding group Id. 2.) The resp group Id was added in /etc/group file. 3.) I made entry in /etc/shadow file also . i am able to login with user iachasta as su - iachasta ... (5 Replies)
Discussion started by: er_aparna
5 Replies
Login or Register to Ask a Question