home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 4.ddi / sbin / deluser < prev    next >
Encoding:
Text File  |  1990-12-08  |  1.7 KB  |  106 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12.  
  13.  
  14. #ident    "@(#)/sbin/deluser.sl 1.1 4.0 12/08/90 35714 AT&T-USL"
  15.  
  16. # delete a user from the system
  17. #    Deluser allows you to remove users from the computer.  The
  18. #    deleted user's files are removed from the file systems and their
  19. #    logins are removed from the /etc/passwd file.
  20.  
  21. rm -f /usr/tmp/addcfm
  22.  
  23. loginid=$1
  24. home=$3
  25.  
  26. if [ $# -lt 3 ]
  27. then
  28.     echo "USAGE: $0 <login id> <Yes/No> <home directory>"
  29.     exit 1
  30. fi
  31.  
  32. if [ "$home" = "" ]
  33. then
  34.     echo "Home directory can't be null"
  35.     exit 1
  36. fi
  37.  
  38. #    check if login name exists
  39.  
  40. grep "^$1:" /etc/passwd >/dev/null
  41. rc=$?
  42. if [ $rc -ne 0 ]
  43. then
  44.     echo "That login doesn't exist on the system."
  45.     exit 1
  46. fi
  47.  
  48. if [ "$2" = "Yes" ]
  49. then
  50.  
  51.     rm -f /usr/mail/${loginid}
  52.  
  53. #
  54. #    Copy all files to lost+found
  55. #
  56.  
  57.     mkdir /lost+found/${loginid}
  58.     cd ${home}
  59.  
  60.     find . -print | cpio -pcvd /lost+found/${loginid}
  61.  
  62. #
  63. #    Remove home directory
  64. #
  65.     cd /
  66.     rm -r ${home}
  67. #
  68. #    Search system for all files owned by loginid
  69. #    Not sure if they want this yet.
  70. #
  71.  
  72. #nohup find / -user $loginid -type f -exec mv {} /lost+found/${loginid} \; > /dev/null 2>&1 &
  73.  
  74. fi
  75.  
  76. #
  77. #    Omit /etc/passwd entry
  78. #
  79.  
  80. /usr/bin/passmgmt -d $loginid
  81.  
  82. #
  83. #    Omit /etc/.useradm entry (if it exits)
  84. #
  85.  
  86. if [ -f /etc/.useradm ]
  87. then
  88.     grep "^${loginid}" /etc/.useradm > /dev/null
  89.     if test $? = 0
  90.     then
  91.         if test -r /etc/adm.lock
  92.         then
  93.             exit
  94.         else
  95.             ed - /etc/.useradm <<-!
  96.             H
  97.             /^${loginid}/d
  98.             w
  99.             q
  100.             !
  101.             rm -f /etc/adm.lock
  102.         fi
  103.     fi
  104. fi
  105.