首页 > 其他 > 详细

bash中for循环添加10个用户和删除10个用户

时间:2016-12-26 14:21:30      阅读:190      评论:0      收藏:0      [点我收藏+]

1. 循环添加10个用户:

#!/bin/bash
#

for i in {1..10}; do
    if id user$i &> /dev/null; then
        echo "user$i exists."
    else
        useradd user$i
        echo user$i | passwd --stdin user$i &> /dev/null
        echo "add user user$i finished."
    fi
done

2. 循环删除10个用户:

#!/bin/bash
#

for I in {1..10}; do
    if id user$I &> /dev/null; then
        userdel -r user$I
        echo "Delete user$I finished."
    else
        echo "user$I not exist."
done


本文出自 “www.aboboo520.com” 博客,请务必保留此出处http://aboboo520.blog.51cto.com/11330424/1886082

bash中for循环添加10个用户和删除10个用户

原文:http://aboboo520.blog.51cto.com/11330424/1886082

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!