How to grep for password file entry


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers How to grep for password file entry
# 1  
Old 03-09-2011
How to grep for password file entry

How would I grep for password file entry without using
grep 'username' /etc/passwd?
perhaps with who?
I want to create alias that will find the password file entry regardless of the user who is using it.

Thanks
# 2  
Old 03-09-2011
use of "id" is fairly portable. You can use that to determine who you are... or you can use whoami. Then, if portability is important, you can use that value (after parsing) to grep into /etc/passwd.

On a Linux box (and some other *ix), you can use getent... e.g.

Code:
getent passwd $(whoami)

# 3  
Old 03-10-2011
the user password file entry in /etc/passwd looks like
Name : Password : UserID : PrincipleGroup : Gecos : HomeDirectory : Shell
this is the format i am trying to accomplish sp if a user was to use the alias they would get this exact file entry with their info
# 4  
Old 03-14-2011
Did you READ my post?

Anyhow.... let's assume you DO NOT have getent first... so a reasonable script might be:
Code:
#!/bin/sh
username=`whoami`
grep "^${username}:" /etc/passwd

One nice benefit of getent over this script would be that multiple sources of auth might be available.... but you DID say just /etc/passwd.... so the above will be sufficient.

No need for an alias here, just put the code above into a script file and make sure it is on the user's PATH.
# 5  
Old 05-19-2011
Or (assuming a normal login took place):
Code:
grep "^${LOGNAME}:" /etc/passwd

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep for first entry in a file?

Hello friends, I have a question. Sometimes I have to search for an entry in a file that is repeated thousands of times. Can you tell me how to search so that i get limited results? For example: file: myfile.txt grep "hello world" myfile.txt this above grep will generate 5000... (4 Replies)
Discussion started by: DallasT
4 Replies

2. Shell Programming and Scripting

Automatic su password entry script

Before I start, two things. 1) Yes I know it's bad practice and obomination to all things holy, but I'm not a sys admin at JP Morgan, I'm a hobbyist tooling about in a VM, in my pants, at home. 2) If you are just going to flame for even considering hardcoding a root password, thanks, I get... (2 Replies)
Discussion started by: 3therk1ll
2 Replies

3. Shell Programming and Scripting

Need to grep certain entry out of log file

This one is a bit too challenging for me... Hopefully you guys can help. Let's say I have a log file called: "$MW_HOME/user_projects/domains/IDMDomain/servers/wls_ods?/logs/wls_ods1-diagnostic.log" In this log file I want to search for "DIP-10219". When I execute this $ cat... (7 Replies)
Discussion started by: exm
7 Replies

4. Shell Programming and Scripting

[awk] grep a part of filename as entry file

hi all, i need to combine these files into one csv file. Bounce_Mail_Event_Daily_Report_01_Jul_2012.csv Bounce_Mail_Event_Daily_Report_02_Jul_2012.csv Bounce_Mail_Event_Daily_Report_03_Jul_2012.csv Bounce_Mail_Event_Daily_Report_04_Jul_2012.csv... (10 Replies)
Discussion started by: makan
10 Replies

5. Shell Programming and Scripting

loop picks up password for 2 entry...how to avoid that ?

hello all, i am trying to find a better to do what i am doing right now... i have a file called sidlist...which has my database_name and password to the respective database so something like below.. file is called sidlist and entry is below... test, abc123 kes12, abcd12 pss, abcd1234... (5 Replies)
Discussion started by: abdul.irfan2
5 Replies

6. UNIX for Dummies Questions & Answers

grep for password file entry

How would I grep for password file entry without using grep 'username' /etc/passwd? perhaps with who? I want to create alias that will find the password file entry regardless of the user who is using it. I am trying to get the same exact line from the file entry like: Name : Password : UserID... (7 Replies)
Discussion started by: alis
7 Replies

7. UNIX for Dummies Questions & Answers

Command to delay password entry - putty connection manager

Hi all, putty connection manager is great but when attempting to sudo or ssh to another box via the post login commands it is subject to issues due to network latency (what happens is that pcm enters the password before the unix box is ready to receive it). Is there any clever way I can make... (1 Reply)
Discussion started by: skinnygav
1 Replies

8. Shell Programming and Scripting

automating username / password entry

I have a database that contains a list of server names, and the password for the root user on several servers (100+). I need to verify the passwords for each of the servers in an automated fashion because the database continues to grow. All of the users that I'm going to test are ROOT. I can't... (1 Reply)
Discussion started by: jbeck22
1 Replies

9. Programming

userpw.h AIX ( delete entry from the shadow password database )

HI i need to delete an entry in /etc/security/passwd. can't find a way to do it with userpw.h api ( AIX ). the passwd file i delete like this. Write all entrys to passwd file except the one we are removing. can't find any function that works like getspent / getpwent do in AIX userpw api.... (4 Replies)
Discussion started by: nighter
4 Replies

10. Programming

/etc/shadow update password entry! ( getspent? )

Hi i just whant to update an password entry in /etc/shadow. But dosen't get it to work. Something is wrong! in this code. What i try do do is if user kalle exist in shadow. I whant it to update it's password for just that entry. #include <stdio.h> #include <errno.h> #include <stdlib.h>... (2 Replies)
Discussion started by: nighter
2 Replies
Login or Register to Ask a Question