So, I have a text file that is organized like this
<username>:<fullname>:<usergroups>
I need to create a new user for each line and put them into their groups. I am stuck with trying to set username into a variable to use with useradd. I have tried using cut but it needs a file name, I can’t just pass it a line.
Here is what I currently have:
#! /bin/bash
linesNum=1
while read line
do
echo
name=$( cut -d ":" -f1 $( line ) )
((lineNum+=1))
done < "users.txt"
Thanks for your help!
fullnameis the only string that should contains whitespace (hence the quotes), A list ofusergroupsshould be separated from the next by a comma, with no intervening whitespace (so no quotes on that argument) and yourusernameshould not contain whitespace either.Upate:
To get the list of
usergroupsto create first you can do this…This is a bit long winded, and could be compacted to avoid the use of the additional files
allgrouplist.txtandgroups.txtbut I wanted to make this easy to read. For reference here’s a more compact version.(I screwed the compact version up a bit at first, it should be fine now, but please note I haven’t tested this!)