<linux小腳本>批量添加/刪除用戶
阿新 • • 發佈:2017-09-09
linux腳本
批量添加/刪除用戶,當輸入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
<linux小腳本>批量添加/刪除用戶