📄 rm_user
字号:
#!/bin/sh5## @(#)removeuser.sh 2.7 (ULTRIX) 3/12/90# Copyright (c) 1984, 1989, 1990 by # Digital Equipment Corporation, Maynard, MA # All rights reserved. # # This software is furnished under a license and may be used and # copied only in accordance with the terms of such license and # with the inclusion of the above copyright notice. This # software or any other copies thereof may not be provided or # otherwise made available to any other person. No title to and # ownership of the software is hereby transferred. # # The information in this software is subject to change without # notice and should not be construed as a commitment by Digital # Equipment Corporation. # # Digital assumes no responsibility for the use or reliability # of its software on equipment which is not supplied by Digital. ## Purpose: To remove a user from the passwd file# Usage: removeuser# Environment: Bourne shell script# Date: 3/20/84# Author: afd# # Remarks:# Removes user from /etc/passwd file, from /etc/group file, and# optionally deletes the user's home directory, all sub-directories# and files.## MODS:# 001 ccb 09-03-86# code compression and acceleration## 002 Wendy Rannenberg 11/16/89# switch to sh5 for internationalization################################################################## modified to work in a SCAMP environment by Jon Wallace## 001 James C. Overman 05-Aug-1990# Moved references to /tmp to /usr/tmp # # Trap ^c signaltrap "" 1 2 3# Lock the passwd and group files/etc/lockpw || exit $?trap '/etc/unlockpw;exit $STAT' 0NL=""MAIL=/usr/spool/mailSTAT=1 # assume failure# Get the user's login nameecho "${NL}Enter login name of user to be removed: \c"read USERcase "$USER" in"") STAT=0;exit ;;*) USERENTRY=`grep "^$USER:" /etc/passwd` || { echo "User $USER not in /etc/passwd file." exit } ;;esac# Display user_entry record from passwd file and confirm it with user.echo "This is the entry in /etc/passwd for user '$USER': $USERENTRY"while :do echo "${NL}Is this the entry you want to delete? (y/n) [n]: \c" read _X_ case "$_X_" in [yY]*) break ;; [nN]* | "" ) echo "${NL}User '$USER' not removed." STAT=0;exit ;; esacdoneecho "Working ..."# Remove the users auth entryif test -f /etc/auth.pag -a -f /usr/etc/sec/rmauth then /usr/etc/sec/rmauth "${USER}"fi# Remove the user from /etc/passwdcp /etc/passwd /usr/tmp/passwded - /usr/tmp/passwd <<EOF/^${USER}:/dwqEOFmv /usr/tmp/passwd /etc/passwdif [ -f /usr/etc/mkpasswd -a -f /etc/passwd.pag ] then echo 'Rebuilding the passwd data base...' ( cd /etc ; /usr/etc/mkpasswd -u passwd )fi# Remove the user /etc/groupcp /etc/group /usr/tmp/grouped - /usr/tmp/group <<EOFg/$/s//,/g/:$USER,/s/$USER,//g/,$USER,/s//,/g/,$/s///wqEOFmv /usr/tmp/group /etc/groupecho "${NL}User '$USER' has been removed from the passwd file, and logins tothat account have been disabled."# free up the password file./etc/unlockpwSTAT=0 # no failure exits beyond this pointtrap '' 0HOMEPATH=`echo $USERENTRY|awk -F: '{print $6}'`while :do echo "Do you want to remove $USER's home directory, subdirectories,and files? (y/n) [n]: \c" read _X_ case $_X_ in [yY]* ) while : do echo "All files and data in user account '$USER' will be destroyed if youanswer 'yes' to the following question. If you are interested inkeeping any information located in user account '$USER', use appro-priate backup utilities to store the information on appropriate mediabefore removing the user account area.Are you sure that you want to remove $USER's files? (y/n) [n]: \c" read _X_ case "$_X_" in [yY]* ) echo "${NL}Deleting $HOMEPATH" rm -rf $HOMEPATH $MAIL/$USER 2>&1 > /dev/null exit 0 ;; [nN]* | "" ) break 2 ;; esac done ;; [nN]* | "" ) break ;; esacdone# 'no'echo "$NL$HOMEPATH not deleted."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -