grep for password file entry


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep for password file entry
# 1  
Old 03-10-2011
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 : PrincipleGroup : Gecos : HomeDirectory : Shell

I was thinking something along the lines
alias me 'whoami \!*; grep /etc/passwd'
but ofcourse this didnt work, its jsut returning the username. I have been at this for hours.

help!

thanks
# 2  
Old 03-10-2011
Like this?
Code:
grep `whoami` /etc/passwd

# 3  
Old 03-10-2011
Belt an braces version of the above:
Code:
grep \^`whoami`: /etc/passwd

# 4  
Old 03-10-2011
no, none of these work so far. I think it will have to be a combination.
Maybe if i get the username first by whoami and then piped to grep for that username in /etc/passwd...is that possible?
# 5  
Old 03-10-2011
Please post a sample file.
Then post what would be sample input, and desired output.

Real questions are often easier to visualize and answer than theoretical.
# 6  
Old 03-10-2011
sorry, yes both the ones above work....Since I am such a big fat NOOB I was using regular quotes instead of backquotes...and I have been trying to get this right since yestaurday ..LOL...and such a simple answer...anyway thanks all.
I chose this for the simplicity and cause the other one with belts did the same exact thing.
grep `whoami` /etc/passwd
# 7  
Old 03-10-2011
Something else to ponder... env variables.
Type env at a prompt, and you will see them all.
Thus,
Code:
grep $USER /etc/passwd

might also do what you want.
 
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 Desktop Questions & Answers

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 (4 Replies)
Discussion started by: alis
4 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