1846627 Members
2151 Online
110256 Solutions
New Discussion

Re: Script help

 
Khashru
Valued Contributor

Script help

I want to write a script that will read a file. the file will contain some login name. If the name is there it will say user is permitted to print other wise not permitted to print.

How can i use this condition in the following script

echo "Enter user name"
read USER
x=`grep $USER user`
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: Script help

The problem with using grep is that if you are searching for 'Bill' then 'Bill', 'Billy', and 'Billie' will match. You need to use enhanced grep and do an anchored search. We are only interested in a match (status 0) or no match (non-zero) so we will use the -q (quiet) grep option.

USERFILE=myusers # file that contains the users"

typeset -i STAT=0
typeset USER=""
echo "Enter user name: \c"
read USER
grep -E -q -e "^${USER}\$" ${USERFILE}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "${USER} OK"
else
echo "${USER} Bad"
fi


If it ain't broke, I can fix that.
Khashru
Valued Contributor

Re: Script help

solved
Muthukumar_5
Honored Contributor

Re: Script help

Hi,

Did you check your profile?

I have assigned points to 18 of 55 responses to my questions.

Try to assign points to reach 55 of 55 responses.

And,

Try to close the thread with answer you got.

--
Muthu
Easy to suggest when don't know about the problem!