Linux often need to delete user actions, manual operation to perform Userdel operation can, if the deletion fails according to the error prompt action. But what if the script needs to invoke the Delete user action? Use the following example to remove the user function Drop_user to maximize the success of the deletion.
Operation Example
#!/bin/BashfunctionDrop_user () {[$#-ne1] && return1Local username=$1 grep-qs/etc/passwd|| Return1 PS-fu"${username}"|grep-Vgrep|awk '{print $}'|Xargs Kill-9&>/dev/NULLUserdel-rf"${username}"&>/dev/NULL&& return0 MV/var/run/utmp/var/run/Utmp_bakTouch/var/run/utmp Userdel-rf"${username}"&>/dev/NULL&& return0|| Return1}# #mainif[ $(WhoAmI) !='Root']; Thenprintf"Please use the root to execute script.\n"Exit1fiif[$#-ne1]; Thenprintf"usage:$ (basename $) username\n"Exit1fiusername=$1Drop_user ${username}if[$?-eq0]; Thenprintf"Drop ${username} success.\n"Exit0Elseprintf"Drop ${username} fail.\n"Exit1fi
[Shell programming] automatically deletes operating system users