i need to find the username in field5 of a user i give in the directory /etc/passwd
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i need to find the username in field5 of a user i give in the directory /etc/passwd
i need to write a script (like vi script1.sh)
so when i type for example:" bash script1.sh user1 "
the script needs to go into /etc/passwd to check if the user excists and then say: user1 excists and his real neam is "whatever stands in the info field behind that user (field 5)"
does anybody has any idea?
i need to write a script (like vi script1.sh)
so when i type for example:" bash script1.sh user1 "
the script needs to go into /etc/passwd to check if the user excists and then say: user1 excists and his real neam is "whatever stands in the info field behind that user (field 5)"
does anybody has any idea?
greetz fly
Yep, lots of them. My first idea is that this sounds like homework.
Post what you've tried already, and we can help you.
The getent program can look up a user. The id program can give you a users uid. These aren't scripts, and are not what your teacher will be looking for if this is a homework assignment. You might want to read "info sed" or "man grep".
finger - user information lookup program
Synopsis
finger [-lmsp] [user ...] [user@host ...]
Description
The finger displays information about the system users.
Last edited by Chromezero; 10-09-2008 at 10:47 AM.
user=`grep $1 /etc/passwd | cut f5 d:`
if test `grep $1 /etc/passwd | cut f5 d:`
then
echo $1 is from $user
else
echo $1 doesn't exists
fi
but then when field 5 is empty, it says: user doesn't excists...
i'll try some of your answers, thx
and yes, it's homework, when i'll take something, i'll make sure i know how to explain it, i'm stupid, but not that stupid
thx all
Flyordie,
that's true. It goes straight to 'doesn't exist' if there is no user or the the 5th field is empty. You will have to add separate statement for checking what 'grep' returns and other to check what 'cut' returns when 'grep' was successful.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.