【shell 练习3】用户管理脚本(一)

一、创建十个用户,密码为八位

[root@localhost ~]# cat UserManger02.sh 
#!/bin/bash
. /etc/init.d/functions
[ $UID -ne 0 ]&&{
   echo "only allow root to exec this cmd."
   exit
} 
dir=/yanglt/
[ ! -d $dir ] && mkdir -p $dir
for n in `seq -w 10`
do
    pass=`echo $RANDOM |md5sum |cut -c 2-9`
    useradd  yanglt$n &>/dev/null &&\
    echo $pass|passwd --stdin yanglt$n &>/dev/null
    if [ $? -eq 0 ];then
        action "useradd yanglt$n" /bin/true
    else 
        action "useradd yanglt$n" /bin/false
    fi
    echo -e "oldboy$n\t $pass" >>/yanglt/user.txt
done
[root@localhost ~]# 

 

posted @ 2018-08-10 01:30  旅行者-Ylt  阅读(338)  评论(0编辑  收藏  举报