批量添加用户

#!/bin/bash

read -p "Enter the User Password : " PASSWD
for UNAME in `cat users.txt`
do
id $UNAME &> /dev/null
if [ $? -eq 0 ];then
 echo "Already exists"
else
useradd $UNAME &> /dev/null
echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null
if [ $? -eq 0 ];then
echo "Create "$UNAME"  success"
else 
echo "Create failure"
fi
fi
done

 

 

 批量删除用户

#!/bin/bash

for UNAME in `cat users.txt`

do
      grep $UNAME  /etc/passwd &> /dev/null
   if [ $? -eq 0 ]
   then
        userdel -r $UNAME
        echo "$UNAME is deleted!" 
   else
        echo "$UNAME is not exist"
   fi
done

 

相关文章:

  • 2021-09-29
  • 2021-12-03
  • 2021-12-27
  • 2021-09-04
  • 2022-12-23
  • 2021-11-20
  • 2021-12-15
猜你喜欢
  • 2021-06-10
  • 2022-01-23
  • 2022-02-08
  • 2022-02-22
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
相关资源
相似解决方案