im trying to create a script that check if user already registered before than add number after username for example username1 and will keep looping after i got unique username.
here what i try
username="tes2"
password="tes2"
exists=$(grep -c "^$username:" /etc/passwd)
case=$exists
i=1
while true
do
case "$case" in
*)
echo 'generate new user'
i=$(( $i + 1 ))
username="$username""$i"
exists=$(grep -c "^$username:" /etc/passwd)
case=$exists;;
0)
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p "$pass" "$username"
echo 'success add $username'
break;;
esac
done
echo "Quit"
when i run this script, it keep generate new user.