Shell Script to add multiple user accounts in a system
if [ $(id -u) -eq 0 ]
then
echo User Input
echo Enter Session:
read ses
echo Enter Department:
read dept
echo Enter Default Password:
read pass
echo Enter the number of user to be added:
read n
mkdir /home/$dept
mkdir /home/$dept/$ses
for ((i=1; i<=n; i++))
do
if [ $i -lt 10 ]
then
stdid=std$ses$dept$i
else
stdid=std $ses $dept$i
fi
homedir="/home/$dept/$ses/$stdid"
usr=$stdid
id $usr &> /dev/null
if [ $? -eq 0 ]; then
echo "$usr exists..."
else
useradd -m -d $homedir $usr
echo -e "$pass\n$pass" | passwd $usr
echo User $usr added successfully.
fi
done
else
echo Only root user can add user.
fi
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.