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

find and replace

Status
Not open for further replies.
Jul 17, 2003
155
US
Hi,

I have this shadow file in a chroot environment.

nobody:NP:6445::::::
noaccess:NP:6445::::::
nobody4:NP:6445::::::
test:eO6/aEEFF$8LA:12249::::::
nobody2:NP:6445::::::
noaccess2:NP:6445::::::

I would like to write a script to find and replace the shadow password where it matches a name. For example, If the script finds the user "test", it will replace the shadow password "eO6/aEEFF$8LA" with a new password.

I am new to scripting. I appreciate any help.

 
Which sort of *nix ?
Have you a
Code:
 passwd
command ?

Hope This Help
PH.
 
on Solaris
I can use the passwd command; but this shadow file is not the same one in /etc/shadow. This shadow file is for use in proftpd.

Thanks,
 
Try this:
Code:
user="test"; newpass="TheNewEncryptedPassword"
sed -e &quot;/^$user:/s!^$user:[^:]*:!$user:$newpass:!&quot; <path/to/shadow >path/to/shadow.tmp && mv path/to/shadow.tmp path/to/shadow

Hope This Help
PH.
 
Solaris Sparc

The shadow file is for used with proftpd. It is not the same file in /etc/shadow.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top