[英]Bash Script To Remove Users From Wordlist
我編寫了以下腳本來從單詞列表中刪除用戶。 詞表有 3 或 4 個字段,分別是名字、中間名、姓氏和用戶 ID。 我正在使用 awk 創建一個用戶名,其中包含用戶的名字首字母、姓氏和他們 ID 的最后兩位數字。 然后使用帶有標志 r 的命令 userdel 來刪除用戶及其主目錄。
但是,當我運行腳本時,它給了我一個錯誤,說明如下:
Usage: userdel [options] LOGIN
Options:
-f, --force force some actions that would fail otherwise
e.g. removal of user still logged in
or files, even if not owned by the user
-h, --help display this help message and exit
-r, --remove remove home directory and mail spool
-R, --root CHROOT_DIR directory to chroot into
-Z, --selinux-user remove any SELinux user mapping for the user
劇本:
#! /bin/bash
# Removing users using positional parameters
getusername(){
line=${1}
len=`echo ${line}|awk '{ FS = " " } ; { print NF}'`
if [[ ${len} -eq 3 ]]
then
initial=`echo ${line}| awk {'print $1'} |cut -c1`
lastname=`echo ${line} | awk {'print $2'}`
id=`echo ${line}| awk {'print $3'}|grep -o '..$'`
username=`echo ${initial}${lastname}${id} |tr '[:upper:]' '[:lower:]'`
elif [[ ${len} -eq 4 ]]
then
initial=`echo ${line} | awk {'print $1'} |cut -c1`
lastname=`echo ${line} | awk {'print $3'}`
id=`echo ${line}| awk {'print $4'}|grep -o '..$'`
username=`echo ${initial}${lastname}${id} |tr '[:upper:]' '[:lower:]'`
else
echo "Line ${line} is not expected as it should be considered for creating Username and Password"
fi
}
sudo userdel -r $getusername
如何調用userdel
?
userdel -r username
這將刪除用戶username的帳戶,並刪除該用戶的主目錄和關聯的郵件文件。
為此,您需要使用變量而不是調用 function。
否則userdel
會抱怨,就像它已經在做或者只是輸入userdel
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.