Creating usrname in /etc/passwd file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating usrname in /etc/passwd file
# 1  
Old 10-20-2003
Creating usrname in /etc/passwd file

I want to create a usrname field for /etc/passwd file consisting of the first letter of the first name and the first 7 letters of the second name. I have got this so far -->

awk -F, '{print tolower(substr($1,0,1)) tolower(substr($1,match($1," ")+1,7))}' file1 > /tmp/data

Where file1 contains : John Doe,users,/bin/sh

However, I failed to realize that some people have punctuations in their name so this would not work if file1 contains ->
John Doe's,users,/bin/sh...
or for that matter -> 'Little John,users,/bin/sh

How do I get what is written into /tmp/data to contain only the first letter of the first name and the first 7 letters of the second name? Numbers can be included as well.

Thanks

Last edited by sleepster; 10-20-2003 at 08:54 AM..
# 2  
Old 10-20-2003
Perhaps you could manipulate a call to adduser after altering the appropriate data?
# 3  
Old 10-20-2003
Your script looks good to me... If your users give you bad data, you will have to filter out the bad characters... OR refuse to add a user if their provided data is bad...

How many users do you add a day/week? IF you have only a few users, it seems like you can just type then out manually to fix bad names.

The useradd command in HPUX is more than sufficent...Im sure your OS has a similar command.
# 4  
Old 10-20-2003
How about this...
Code:
#!/usr/bin/ksh
typeset -L1 f1
typeset -L6 l6
typeset -l username

IFS=,
while read name group shell ; do
        fname=${name%% *}
        lname=${name##* }
        fname=$( echo $fname | sed 's,[^0-9a-zA-Z],,g')
        lname=$( echo $lname | sed 's,[^0-9a-zA-Z],,g')
        f1=$fname
        l6=$lname
        username=${f1}${l6}
        echo $username
done
exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords?

Does anyone know when AIX started using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? (1 Reply)
Discussion started by: Anne Neville
1 Replies

2. UNIX for Dummies Questions & Answers

help with passwd file

Not an unix expert, I read a few pages on the web about passwd files, but I didn't find the answers I need about the last 8 lines of the passwd file I'm taking a look at. I'm assuming their shortcuts to another file that may have the actual usernames of users on the system. Please, any help... (1 Reply)
Discussion started by: fusion31
1 Replies

3. Solaris

passwd cmd reenables passwd aging in shadow entry

Hi Folks, I have Solaris 10, latest release. We have passwd aging set in /etc/defalut/passwd. I have an account that passwd should never expire. Acheived by emptying associated users shadow file entries for passwd aging. When I reset the users passwd using passwd command, it re enables... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

4. UNIX for Dummies Questions & Answers

FTP thru Unix doesn't auth usrname & pswd, but Windows app does - why?!

Strange one this... One of our contacts switched FTP servers, a different IP and now using port 2121 instead of 21. Changed the details in a Windows application using the username & password provided and it works no problem. Tried to FTP through Unix and although I can connect to the... (2 Replies)
Discussion started by: macca74
2 Replies

5. UNIX for Dummies Questions & Answers

Creating a copy of the /etc/passwd file

Is there a command for creating a copy of the /etc/passwd file named "./copy-passwd" that contains only the entries for userids that have a home directory in /home/inst, and change each entry in your copy so that the default login shell is /bin/sh. (2 Replies)
Discussion started by: raidkridley
2 Replies

6. UNIX for Dummies Questions & Answers

apache passwd file

i am using apache2.0, and i used this command to create username/passwd: ./htpasswd -b passwd.file username password is it away to translate password back to plaintext ? for example, passwd.file contains: username:HnennjvqsGaQs i want to translate back to: username:password (1 Reply)
Discussion started by: tjmannonline
1 Replies

7. UNIX for Advanced & Expert Users

Recovery Of Passwd File

the file /etc/passwd has corrupted mistakenly.actually the file has saved as "oot:0:0:root:/root/sbin/bash". first r of root has been deleted .. can anyone tell me how can i recover as normal user (2 Replies)
Discussion started by: singh_hackerz
2 Replies

8. Shell Programming and Scripting

help in /etc/passwd file

Hi all, As all of us know that in /etc/passwd file the first field correspond to username could any one tell me what is bin , damoen etc in the first field, and r they in user field , what is nologin in the last column ? root:x:0:0:root:/root:/bin/bash ... (4 Replies)
Discussion started by: useless79
4 Replies

9. Cybersecurity

/etc/passwd file

hi Does anyone anyone know what the last line of a unix user passwd file signifes? Mine shows "+:::::" best (4 Replies)
Discussion started by: s_mad010
4 Replies

10. Shell Programming and Scripting

Creating an entry for /etc/passwd

given an input file containing fields seperated by "," how do I retrieve information of these fields, do some work on them, then create a new input to the etc/passwd file? someone told me to look at the "sed" command but I still cant seem to get over this problem. I want to work on the data so... (8 Replies)
Discussion started by: sleepster
8 Replies
Login or Register to Ask a Question