Operating System - HP-UX
1831111 Members
2629 Online
110020 Solutions
New Discussion

Script do compare and delete

 
SOLVED
Go to solution
Vogra
Regular Advisor

Script do compare and delete

Hi All!
How can I solve the problem below:
I need to clean de passwd file from old users. I have a $list that have users not able to access the system. I have to make a script that read a line (first n characters) from passwd file, compare this with this list and, if it's match, delete the line from passwd file.
We are spirits in the material world
4 REPLIES 4
John Poff
Honored Contributor

Re: Script do compare and delete

I'd suggest feeding your list to the userdel command and letting it do the work for you.

Vincenzo Restuccia
Honored Contributor
Solution

Re: Script do compare and delete

while read i
do
userdel -r $i
done < list
A. Clay Stephenson
Acclaimed Contributor

Re: Script do compare and delete

Hi,

Before you run this script, I would surround the userdel command with something like:
if [ "${i}" != "root" ]
then
userdel -r ${i}
fi

AND
1) Make sure that you are logged in as root in at least two sessions
2) you have a copy of the passwd file
This way you can get yourself out of possible trouble as fast as you got yourself into trouble.

Regards, Clay
If it ain't broke, I can fix that.
Vogra
Regular Advisor

Re: Script do compare and delete

Vincenzo and Clay,
thank you so much for your help. It's ran fine.
We are spirits in the material world