批量添加/删除用户,当输入add时,判断用户是否存在,存在则显示存在,不存在则添加;当输入del时,判断用户是否存在,存在则删除用户,不存在则显示不存在。
#!/bin/bash
if [ $1 == "add" ];then
for i in {1..10}; do
if id user$i &> /dev/null;then
echo "the user$i exists!"
else
useradd user$i &> /dev/null
echo "user$i" | passwd --stdin user$i &> /dev/null
echo "user$i creat success!"
fi
done
elif [ $1 == "del" ];then
for i in {1..10};do
if id user$i &> /dev/null;then
userdel -r user$i
echo "user$i deleted"
else
echo "user$i not exists!"
fi
done
else
echo -e "unknown arguments"
fi
本文出自 “11944248” 博客,请务必保留此出处http://11954248.blog.51cto.com/11944248/1963799
小脚本>批量添加/删除用户' ref='nofollow'>
原文:http://11954248.blog.51cto.com/11944248/1963799
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!