Matching user alias's to their ID's in the passwd file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching user alias's to their ID's in the passwd file
# 1  
Old 06-15-2012
Matching user alias's to their ID's in the passwd file

Hi,
I've a user alias file in the below format.. I need to change all the ID's that come after the = sign (with some multiple ID's which are separated by comma's) to their respective users that are contained in the passwords file.. Whats the best way to go about this.. Some sort of sed command in a loop using grep?

I'm really not familiar with this kind of stuff...

Alias File format
Code:
KVHPOJNOTES=x1565275,x0997695
INES=uc00275,uc01522,uc00286,uc01640,uc01672,uc01940,uc01941
KVHNOTESIDAHMLB=ahml02
KVHNOTESIDAHUBA=ahub01,uc01640
KVHNOTESIDALMLD=alml02
KVHNOTESIDALMLE=alml04


If I changed the file that all the deliminators (the = and ,) were a space, would it start off something like this?

Code:
awk -F" " '{ for ( i=2; i<=NF; i++ )


Last edited by Scrutinizer; 06-15-2012 at 02:53 PM.. Reason: quote to code tags
# 2  
Old 06-15-2012
Code:
[root@node2 ~]# cat infile 
KVHPOJNOTES=x1565275,x0997695
INES=uc00275,uc01522,uc00286,uc01640,uc01672,uc01940,uc01941
KVHNOTESIDAHMLB=ahml02
KVHNOTESIDAHUBA=ahub01,uc01640
KVHNOTESIDALMLD=alml02
KVHNOTESIDALMLE=alml04

[root@node2 ~]# cat passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync

[root@node2 ~]# awk -F[:=] 'NR==FNR{a[FNR]=$1}NR>FNR{$1=$1"="a[FNR];print $1}' passwd infile 
KVHPOJNOTES=root
INES=bin
KVHNOTESIDAHMLB=daemon
KVHNOTESIDAHUBA=adm
KVHNOTESIDALMLD=lp
KVHNOTESIDALMLE=sync

# 3  
Old 06-15-2012
Another interpretation of post #1 . Look up each alias in /etc/passwd .

Code:
cat alias.lst | cut -f2 -d= | tr ',' '\n' | sort | uniq | while read username
do
        echo "Checking username: ${username}"
        grep \^${username}: /etc/passwd
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using alias after issuing 'su - user'

Hi, Using ksh, I have set up aliases (which work fine) in my user's .profile like this: alias ll = 'ls -lrt' alias cls = 'clear' How do I call these same aliases so that they will work after issuing this: ? su - user I do not want to add aliases to the su shell's .profile or .kshrc. (7 Replies)
Discussion started by: ocbit
7 Replies

2. UNIX for Advanced & Expert Users

Passwd file define user with special character

Hi all , The FTP user defind in my passwd file has ! in the hash password field and i want to know way is that its usually either MD5(Unix) hash or * can anyone explain to me i'm new for unix and want to learn this how my passwd file looks : ... (2 Replies)
Discussion started by: dahash11
2 Replies

3. UNIX for Dummies Questions & Answers

User info not present in passwd file

I have logged into a box with some userid,but in this box der is no entry for this userid in /etc/passwd file.this box is used by multiple users but none of them have their enteries in passwd file but for each user there is a directory in /home like for user1 /home/user1 for user2... (5 Replies)
Discussion started by: Jcpratap
5 Replies

4. Shell Programming and Scripting

matching user input to a text file loop?

until do read -p "Invalid cars. Try againa" cars1 done Ok i have the above code, im getting users input and if it doesnt match in the file the user has to try again untill its correct But when i run this it gives me an error saying ./Cars.bash: line 43: (2 Replies)
Discussion started by: gangsta
2 Replies

5. Programming

C++ - Problem in asking and checking user's passwd

This is the source code: #include <pwd.h> #include <iostream> #include <string.h> using namespace std; int main() { struct passwd *user; char login="alex", password="qwertyuiop"; if ((user= getpwnam(login)) == NULL) cout << "No such user\n"; else if... (24 Replies)
Discussion started by: hakermania
24 Replies

6. UNIX for Advanced & Expert Users

Determining if user is local-user in /etc/passwd or LDAP user

Besides doing some shell-script which loops through /etc/passwd, I was wondering if there was some command that would tell me, like an enhanced version of getent. The Operating system is Solaris 10 (recent-ish revision) using Sun DS for LDAP. (5 Replies)
Discussion started by: ckmehta
5 Replies

7. Shell Programming and Scripting

Unix Script to search user id in /etc/passwd

Hey all, i have to write a script in Unix that would help me in my department to search certain user ids valid in /etc/passwd file.. here goes the exact question & data to help analyze: Amend a script to tell the user to enter a user id to be searched for in the /etc/passwd file. If there are no... (7 Replies)
Discussion started by: ally_d
7 Replies

8. UNIX for Dummies Questions & Answers

How the /etc/passwd file is written when user does not have permission

Hi, /etc/passwd file has write permission only for the root user. Now when a normal user changes the its own password using passwd command, how this information has been written to the /etc/passwd file when the user is not having write permission to this file. ~santosh (2 Replies)
Discussion started by: santosh149
2 Replies

9. Shell Programming and Scripting

Looking for specific user ID's from the passwd file

Hello, My issue is that I want to look for specific users that have their first and last initial followed by four numbers. For example: ab1234 I've already got the user ID's out of the passwd file more passwd | awk -F ":" '{print $1}' > userids I just need to know how to just pick... (8 Replies)
Discussion started by: LinuxRacr
8 Replies

10. UNIX for Dummies Questions & Answers

User should not be allowed to change passwd

Hi Group, Can anyone assist me with this? I am on AIX 5.2 ML06. I create the user and assign a passwd. But I do not want the user to change the passwd at all. I like him/her to use the passwd that I have set for him/her. Any ideas would be highly appreciated!!! Thanks. (3 Replies)
Discussion started by: brookingsd
3 Replies
Login or Register to Ask a Question