I have a txt file called Usernames.txt with such information (name followed by group type). E.g. (These are the few instances as there are way more inputs.)
Usernames.txt:
ellipsiscoterie,visitor
magnetcommonest,visitor
belateddefensive,staff
wizardmeans,visitor
bobstercaramelize,staff
In the script show below, I attempted to add each line's name as a user and allocate each new user to its respective groups. However I have encountered this error. And the output is not what I had in mind. I hope someone can help me out, thanks.
Basically this is what I want to do but for every single lines in the txt file.
E.g. sudo useradd bobstercaramelize
(which is the name of user) and sudo usermod -a -G staff bobstercaremelize
.
Error:
createUsers.sh: line 4: $'[visitor\r': command not found
Code:
#!/bin/bash
while read line; do
arrIN=(${line//,/ })
if [${arrIN[1]} = "visitor" ]; then
sudo useradd ${arrIN[0]}
sudo usermod -a -G visitors ${arrIN[0]}
else
sudo useradd ${arrIN[0]}
sudo usermod -a -G staff ${arrIN[0]}
fi
done < Usernames.txt