1755258 Members
5020 Online
108831 Solutions
New Discussion юеВ

Another easy one...

 
SOLVED
Go to solution
TheJuiceman
Super Advisor

Another easy one...

Here's another one. What is an easy way to test if a user exists on a system? I want to test for a user's existence and then use that ID to chmod a directory. Thanks.
2 REPLIES 2
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Another easy one...

Hi Bobby,

There are quite a few ways like grepping the user from /etc/passwd, commands like logins, id etc.,. I use 'pwget'.

USER=Your_user_name
pwget -n $USER |grep -q "^${USER}:"
if [[ $? = 0 ]]
then
Your_chmod_commands
else
echo "$USER does not exist"
fi


-Sri
You may be disappointed if you fail, but you are doomed if you don't try
TheJuiceman
Super Advisor

Re: Another easy one...

Sri, you are awesome!!! I never would have come up with that. Thanks a million for the help!!!