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!

Script for deleting numerous ids?? 1

Status
Not open for further replies.

suntech

IS-IT--Management
Mar 21, 2002
7
US
Example, There are 150 ids with a GID of 500. I have been given a list of 100 ids that need to be deleted within this group (500). Rather than go into admintool and do each one individually, is there a script I could use?

The script would ask what GID?
Once the GID was entered it would pull up each id within that GID one at a time, prompting me with a choice to delete "Y" or "N"
If "Y" is selected, it would remove that id from /etc/passwd and /etc/shadow and perhaps give me the choice to also delete their home directory.

 
Why not use the command userdel -r <loginname>? The -r deletes the home directory.

You could have a list of the users you want to delete, do a read of the list and delete those who are in the list.
 
[tt]#!/bin/ksh

echo &quot;What GID? \c&quot; ; read GID

exec 3<&0

nawk -F: '$4==&quot;'$GID'&quot; { print $1 }' /etc/passwd | while read USER
do
echo &quot;Remove $USER? \c&quot; ; read -u3 YN
if [[ &quot;$YN&quot; == [yY] ]]
then
echo &quot;Remove home directory too? \c&quot; ; read -u3 YN
if [[ &quot;$YN&quot; == [yY] ]]
then
userdel -r $USER
else
userdel $USER
fi
fi
done

exec 3<&-[/tt]

The script duplicates standard input (exec 3<&0) to allow it to read from both the nawk output and the user separately. Annihilannic.
 
My problem:

I am unable to identify and trace down the error display:

SUNW,hme0:LinkDown - cable problem ?
 
Please start a new thread if you have a new, unrelated issue.

That error means that one of your network interfaces doesn't have a cable connected, or there is some problem with the network cable, network switch, etc. Annihilannic.
 
Annihilannic, thank you so much, it works like a charm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top