#!/bin/bash # Author: 电脑程序爱好者 # Date & Time: 2021-04-26 10:03:59 # Description: for i in test{1..5}; do useradd $i pass=$(date +%s | md5sum | cut -c 1-8) # 建立随机密码 sleep 1s echo "$i:$pass" >>/tmp/passwd.log echo "$pass" | passwd --stdin $i #echo "$i:$pass" | chpasswd # for ubuntu OS if [ $? -eq 0 ] ; then echo "create user successfully! user:$i,password:$pass" else echo "failed to create user." fi done