libo 发表于 2018-9-24 15:30:05

脚本系列(三)从文件中读取用户名密码进行批量创建


#!/bin/bash
file=/root/shell/passwd.txt
while read line
do
   user=`echo "$line" | awk '{print $1}'`
   pass=`echo "$line" | awk '{print $2}'`
   if [[ `cat $file | wc -l` -eq 0 ]];then
      echo "文件是空的"
   else
      echo "$user"
      echo "$pass"
      useradd $user
      echo "$pass" | passwd --stdin $user &>/dev/null
      if [ $? -eq 0 ];then
          echo "user is create"
      fi
   fi
done<$file
页: [1]
查看完整版本: 脚本系列(三)从文件中读取用户名密码进行批量创建