shell--寫一個腳本,批量創建10個用戶用戶名為userAdd1-10,並給他們隨機密碼


1,創建十個用戶,並且給予隨機密碼,並將密碼保存到一個文件中

#!/bin/bash
##############################################################
# File Name: add.sh
# Version: V1.0
# Author: ZhangHongLiang
# Organization: 
# Created Time : 2017-12-08 11:55:42
# Description:
##############################################################
source /etc/init.d/functions
for((i=01;i<=10;i++));do
user=addUser$i
password=`uuidgen`
  echo "$user" >>/tmp/pass.txt
  echo "$password" >>/tmp/pass.txt
  echo "--------------------$user--------------------"
useradd $user
  if [ $? != 0 ];then
    action "user $user" /bin/false
    exit 1
    else
    action "user $user" /bin/true
fi   
echo "$password"|passwd --stdin $user
  if [ $? != 0 ];then
    action "user $password" /bin/false
    exit 1
    else
    action "user $password" /bin/true
fi   
  echo "--------------------$user--------------------"
done

2.創建一個腳本,批量刪除上一個腳本所創建的用戶

#!/bin/bash
##############################################################
# File Name: userdel.sh
# Version: V1.0
# Author: ZhangHongLiang
# Organization: 
# Created Time : 2017-12-08 17:18:18
# Description:
##############################################################
. /etc/init.d/functions
for((i=1;i<=10;i++));do
user=addUser$i
userdel -r $user
  if [ $? != 0 ];then
    action "userdel $user" /bin/false
    exit 1
    else
    action "userdel $user" /bin/true
fi
done

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM