Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

check username

SOLVED
Go to solution
Mauro Gatti
Valued Contributor

check username

Hi All, I'd like to know if exists a way to check if a given userid esists on system or not.
I'd like to have an exit status like 0 = exist 1 = doesn't exist...
Do You know what I can do?

Thank you
Ubi maior, minor cessat!
5 REPLIES
Pete Randall
Outstanding Contributor
Solution

Re: check username

grep username /etc/passwd

Pete
Jose Mosquera
Honored Contributor

Re: check username

Hi,

This way is full specific user's name retrieval:

#grep ^username: /etc/passwd

Rgds.
T G Manikandan
Honored Contributor

Re: check username

#logins|awk -F " " '{print $1}'|grep

Robin Wakefield
Honored Contributor

Re: check username

Hi,

If you want to check NIS too, then maybe use perl:

var=`perl -e '{print ! (defined getpwnam shift)|| 0}' username`

this will give you the return codes as in your question.

rgds, Robin
Norman_21
Honored Contributor

Re: check username

Hi,

Another way,

#more /etc/passwd
press and type the user name you are looking for.
e.g) \username and press Enter key get the result.

Thanks.
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003