Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have tried to figure this out and I frankly have no idea how to get this to wo

ID: 3819064 • Letter: I

Question

I have tried to figure this out and I frankly have no idea how to get this to work. I am supposed to design a script that takes a user supplied username and checks to see if the username exitis. If it does not exist, the script is supposed to say "No user found." That part I can get to work.

However, I cant get the part that looks to see if a username exists to work. If the user name does exist, it is supposed to printou the passwd/account information for the user. I tried using the getent command but that just continuously renders the "No user found" part of my If/else statement. I asked a few classmates and they seem to be using grep and their code looks something like this SEARCHSTRING=`grep -h $1 ~/SLASH/etc/group | grep :x:`

I get that the example code is searching etc/group and not etc/passwd. However, can anyone help me understand how i am supposed to use grep, along with an IF/Else statement, to accomplish this assignment. I have spent 6 hours on this and cant seem to figure it out.

Explanation / Answer

ANS: The following are the scripts..The comments are followed by '#' .Thank you.

method -1

#userExist func

UserExist()

{

# $1 for user crediantials like password which you want

awk -F":" '{ print $1 }' /etc/passwd | grep -x $1 > /dev/null

#return $

return $?

}

# checking userExist with $1

UserExist $1

#if equals 0 then exists

if [ $? = 0 ]; then

echo "$1 exists."

echo $1

#echo doesnt exit

else

echo "$1 does not exist."

#fi

fi

#end

M-2::

If you want to hash user passwrd

shadow can be used,, grep username:

//cat /etc/shadow | grep username//

//openssl passwd -1 -salt TrOIigLp//