添加用戶
從文件中讀取將要創建的用戶名
account201.txt 內容:
#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin # check account.txt is exits 從文件中讀取將要創建的用戶名 account_file="account201.txt" # 如果文件不存在 if [ ! -f $account_file ]; then echo "Don't have accout.txt" exit 1 fi usernames=$( cat $account_file ) for username in $usernames do ·# 添加用戶 useradd $username # 設置 密碼同用戶名 echo $username:$username | chpasswd # 設置新用戶在第一次登陸時自己重置密碼 chage -d 0 $username echo -e "echo -e \"\033[36m made by lsx \033[0m\"" >> /home/$username/.bashrc done echo "Create accounts successfully!"
批量刪除:
del_accounts.txt 內容
#!/bin/bash#houyanzhi create it to delete student's PUTTY accounts last year export PATH=/bin:/sbin:/usr/bin:/usr/sbin # check account.txt is exits account_file="del_account.txt" if [ ! -f $account_file ]; then echo "Don't have accout.txt" exit 1 fi usernames=$( cat $account_file ) for username in $usernames do
# 刪除語句
userdel -r $username done echo "Delete accounts successfully!"