I'm looking at a away of reading the username and password of a file and inputing those to either add user or delete user.
EG: I have a file named 'userlist' with the following content with this format:
user1 pass1
user2 pass2
user3 pass3
What I don't understand completely is how to use BASH script to add these accounts.
What I have so far is this:
if [[ whoami -ne "root" ]]
then
exit
else
echo "wish to add or delete? a/d"
read uArg
echo "enter file name"
read uFile
if [ $uArg = "a" -o $uArg = "A" ]
then
IDK WHAT TO DO HERE.
elif [ $uArg = "d" -o $uArg = "D" ]
then
IDK WHAT TO DO HERE.
fi
fi
Alright, what I don't understand is how to read each word line by line and input the username and password to add a new user or delete an existing user.
The program is ment to read the whole file and add each user with there corrosponding password. If delete is chosen then it deletes each user within the file.
I'm new to BASH so any help would be greatyl appreciated.
First comments:
Could be something along these lines:
awk
perfectly feets your needs.See this example:
Awk stores usernames in $1 and passwords in $2 (first and second column).
You can use pipelines to execute the strings you get from awk as commands:
something along the lines of...