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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retain alphabetic case?

Status
Not open for further replies.

lrintx

Technical User
Dec 10, 2010
1
US
Hello

I am trying to replace a password in a Solaris shadow file that is locked with a new passwd, but I can not get it to retain my upper case characters.

This is a one liner that works, but it doesnt retain the case.

I am very new at this, but here is what I have:

perl -spi -e 's/^'\newuser:\*LK\*:/'\newuser:\$1\$\jdksWPrA\$\LeYykxnNPhUD8RXP8SpHyt\/\:/' /etc/shadow

Would someone please help me and tell me how to retain my uppercase characters. I have tried /i for ignore and it didnt do anything.

TIA

LA
 
I don't have a Solaris shadow file available, but if I remember correctly they are identical in syntax to Linux's which I have to look at, and what you are trying to match really seems strange. Even to the point that it would match anything. I don't see anything that suggests that case wouldn't be retained.

You start with ^\newuser, are you backslashing a normal 'n'?
Second in the password field you have \*LK\*, which is to say they only thing it will match *LK*, no wild cards. Is that what is intended that new users always have a simple 4 character one?

The /i is for ignoring case in the match, has nothing to do with how the replacement works. This would be much easier if you put it in a file and were not fighting the command line trying to expand stuff on top of Perl doing the same.

Anyway here is a working line provided I read your escaped password right (It doesn't care what the old password is):
$1$jdksWPrA$LeYykxnNPhUD8RXP8SpHyt

perl -spi -e 's/^(newuser:)[^:]*/$1\$1\$\jdksWPrA\$\LeYykxnNPhUD8RXP8SpHyt/i' ./shadow


OR just so you can pick out the password

perl -spi -e 's/^(newuser:)[^:]*/$1NewPassword/i' ./shadow

It reads like this
^(newuser:) match newuser: at the beginning of the line (even if it is NewUser:) the () around the newuser: says save this in $1, [^:]* match zero or more characters that are not : (The old password)

Replace what was matched with:
$1 <- (saved from (newuser:) match just so I don't have to repeat newuser: twice or if wild cards were used and I really don't know the full username) and then NewPassword (notice the old password was matched, but not put back so it will be replaced with the new password). Since the rest of the line was not matched it will not be changed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top