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

Delete users Home directory 1

Status
Not open for further replies.

KPKIND

Technical User
Sep 8, 2003
130
IN
Hi *,

Is there anyway where I can specify to delete the user's home directory, without me going and deleting it explicitly.

TIA
KPKIND
 
Hi,

No way, when you delete a user, only entries in files modeling users database are deleted : /etc/passwd, /etc/group, /etc/security/passwd )
The home directory and files that it contains must be deleted separatly.
 
Oh, Thanks a lot... That is what I was also thinking... But thought if anyone had any better way of doing it..

Cheers
KPKIND
 
Code:
#!/bin/ksh
for i in $@
do
  lsuser $i >/dev/null 2>&1 || { echo $i is not a known user; exit; }
  rm -rf ~$i
  [[ -f /usr/spool/mail/$i }} && rm /usr/spool/mail/$i 
  rmuser $i
done
Can anyone think of anything I have missed?

Columb Healy
 
This is a script I have in /usr/local/bin and allow a select few on our helpdesk to run it using sudo

Code:
#!/bin/ksh
#############################################################
#  Created: 09/09/2004
#  Arguments: username of user to remove
#############################################################

Num_of_exp_args=1

if [ $# -ne $Num_of_exp_args ] ; then
        echo "Usage: `basename $0` username"
        exit 3
fi

USER=$1

lsuser $USER > /dev/null 2>&1
if [ $? -eq 0 ] ; then
   printf "Removing user $USER\n"
   rmuser -p $USER
   printf "Removing /home/$USER\n"
   rm -rf /home/$USER
   if [ -f "/var/spool/mail/$USER" ] ; then
      printf "Removing /var/spool/mail/$USER\n"
      rm -f /var/spool/mail/$USER
   else
      printf "$USER had no mail\n"
   fi
   printf "$USER has been removed\n"
else
   printf "$USER does not exist\n"
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top