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? greetz fly |
Quote:
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".
|
To actually answer your question... it can be something like this:
Code:
#!/bin/bash |
Here's a script for you. Remember, though, that if it's a homework problem, you'll need to be able to explain it to your instructor:
Code:
#!/bin/bash |
You could use "finger" and save a few steps...
Code:
finger - user information lookup program |
i tried it this way
Code:
user=`grep $1 /etc/passwd | cut f5 d:` 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 :p thx all greetz fly |
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. |
All times are GMT -5. The time now is 03:40 AM. |