1846380 Members
3380 Online
110256 Solutions
New Discussion

replacing text

 
Donna Powell
Advisor

replacing text

I am in the process of writing a script to replace the encrypted passwd in the passwd file with an asterik. So far I have only been able to grep this information from the passwd file using grep inconjunction with the awk command, but I can't figure out how to replace this information with an asterik. Any help will be appreciated.
5 REPLIES 5
Jordan Bean
Honored Contributor

Re: replacing text


`passwd -l ` does this.



Joseph C. Denman
Honored Contributor

Re: replacing text

I agree, I would use the -l option.

However, if you wish to use sed.

first, you would have to cut -f2 of the passwd file for the user (lets say $var1) then

cat /etc/passwd | sed 's/$var1/\*/' > /etc/passwd.tmp

then
mv /etc/passwd.tmp /etc/passwd

...jcd...
If I had only read the instructions first??
A. Clay Stephenson
Acclaimed Contributor

Re: replacing text

Hi Donna,

On the earlier releases of HP-UX passwd -l is not available. I had a script that was very close and spent about two minutes adapting it to your needs. The final copy of the temp file to /etc/passwd is commented out for testing.

Use it like this: clobber user1 user2 ...

It will place an * in the passwd field of user1 user2 ...; there is a value min_uid (100). No change will be made to a user with a UID less than this value. You can set it to another value.

Whenever you are manipulating the passwd file like this, make sure that you make a safe copy of the passwd file and be logged in as root in two sessions. TYou are then able to extricate yourself from a problem as fast as you got yourseld in it.

Regards, Clay
If it ain't broke, I can fix that.
Donna Powell
Advisor

Re: replacing text

Thanks UNIX friends. I'll try the passwd -l command
James R. Ferguson
Acclaimed Contributor

Re: replacing text

Hi Donna:

How about this:

awk -F: 'BEGIN {OFS=":"};{if ($3>=100 && $2!="*") {$2="*";print $0} else {print $0}}' /etc/passwd > /tmp/passwd

This will preserve UID's less than or equal to 100 but will alter those greater than 100.

Regards!

...JRF...