Linux运维必会的实战编程笔试题(19题)
企业面试题4:
批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串)。
#!/bin/bash # for((i=1;i<=10;i++)){ if [ $i -lt 10 ];then j=0$i else j=10 fi id user$j &> /dev/null if [ $? -ne 0 ];then useradd user$j &> /dev/null password=`openssl rand -base64 8 | cut -c -8` echo $password | passwd --stdin user$j &> /dev/null echo "user$j created, password is $password." else echo "user$j already exiests." fi }
运行:
删除测试产生的用户
运行结果:
done