Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help?!! Nearly there shell variable stuck 1

Status
Not open for further replies.
Oct 22, 2004
26
Below is my script but I only want GID 102 to have password chagned but I'm unsure how makre the shell script a variable

echo "Please enter the username that you are wanting to change. Remember that
you must set the password to 123456"
read username
*****more /etc/passwd |grep $username |awk -F: '{print $4}'
read display*****
if test "$display" = "102"
then
passwd $username
passwd -f $username

. /opt/bin/useradm.mnu
elif
echo "You don not have access to change this password. Please press ENTER to
exit"
read exit
then
. /opt/bin/useradm.mnu
fi
 
It would help to know in which shell this script is to be used. Here are some ideas that should help:

display=`grep $username /etc/passwd | awk -F: '{print $4}'`
if [ $display -eq 102 ]
then
<code you want for GID = 102>
else
echo "You do not have access . . ."
read exit
fi

I hope that helps you.

Mike
 
Thanks Mike
comes to the first part eg put a name in then exits out!!! the shell is bin/sh I think!

echo "Please enter the username that you are wanting to change. Remember that
you must set the password to 123456"
read username
display='grep $username /etc/passwd | awk -F: '{print $4}'`
if [ $display -eq 102 ]
then
passwd $username
passwd -f $username
exit
else
echo "You don not have access to change this password. Please press ENTER to
exit"
read exit
fi
 
Please be very careful to distinguish between ` (back-tick) and ' (single quote). The line display=`grep $username /etc/passwd | awk -F: '{print $4}'` has 2 back-ticks and 2 single quotes.
Also you don't need the exit before the else.

I hope that helps.

Mike
 
Sorry mike I starting to feel stupid!!
when I type the name

Please enter the username that you are wanting to change. Remember that
you must set the password to 123456
dochertr
./pass1.sh: [: too many arguments
You do not have access to change this password. Please press ENTER to
exit

Script

echo "Please enter the username that you are wanting to change. Remember that
you must set the password to 123456"
read username
display=`grep $username /etc/passwd | awk -F: '{print $4}'`
if [ $display -eq 102 ]
then
passwd $username
passwd -f $username
else
echo "You don not have access to change this password. Please press ENTER to
exit"
read exit
fi
 
Don't worry, we all started scripting sometime.
There are several shells for which people write scripts. I personally prefer Korn. The "if" statement in your script should work in Korn (ksh) and Bourne (sh), as I have just tested it on one of our Sun systems running Solaris 8. To force the script to use the Korn shell, insert the following line at the top of the script:
#!/bin/ksh

Just because the script is called pass1.sh doesn't mean it will run as a Bourne shell script.

I hope that helps.

Mike
 
I tell you my head hurts!!!! Cheers I'd be here for the next month trying to figure it out.

just tried it Spot on!! I can now change the rest of my little programs would ask about log/audit trail but we'll leave that till next time!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top