test-user-1,test-user-1
test-user-2,test-user-2
test-user-3,test-user-3
test-user-4,test-user-4
#!/bin/sh
# read filename
filename="$1"
# check if the file exists
if [ ! -f "$filename" ]; then
echo "File not found."
exit 1
fi
# read file contents line by line
while IFS=, read -r username password; do
# check if the user exists
#if id "$username" &>/dev/null; then
if id "$username"; then
echo test
echo "User '$username' already exists."
else
# create user
useradd "$username"
# set user's password
echo "$username:$password" | chpasswd
echo "User '$username'."
fi
done < "$filename"