#!/bin/bash
if [ -z "$1" ]
then
echo please give me a userfile
elif [! -e "$1" ]
then
echo "$1 is not exist!!"
else
for NAME in `cat $1`
do
USER=`getent passwd $NAME`
while [ -n "$USER"]
do
echo $NAME is exist!!
exit 1
done
useradd $NAME
echo westos | passwd --stdin $NAME
done
fi
if [ -z "$1" ]
then
echo please give me a userfile
elif [! -e "$1" ]
then
echo "$1 is not exist!!"
else
for NAME in `cat $1`
do
USER=`getent passwd $NAME`
while [ -n "$USER"]
do
echo $NAME is exist!!
exit 1
done
useradd $NAME
echo westos | passwd --stdin $NAME
done
fi
本文介绍了一个使用bash编写的脚本,该脚本可以从文件中读取用户名并为每个用户名创建系统用户。如果文件不存在或格式不正确,脚本会给出相应的错误提示。
1386

被折叠的 条评论
为什么被折叠?



