LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-22-2017, 02:52 AM   #1
Oblivionsmist
LQ Newbie
 
Registered: Oct 2017
Posts: 6

Rep: Reputation: Disabled
Linux Scripting How to add multiple users at once from a text file


Hi, I have a text file called userlist.txt which contains a bunch of names:

Aline Kurek *
Wendy Aldridge *
Darla Tan *
Marni Buenrostro *
Rosalina Salinas *
Eleonore Gibby *
Simon Flanigan *

i need to write a script which will add all the users from the .txt file with the useradd command.
+ remove the spacing in between their names e.g AlineKurek
+ assign a password based off of their names e.g AlineKurkek123

I can't seem to get it working this is my code so far:

#!/bin/sh
awk '{$1.$2}' /home/Documents/userlist.txt
for i in /home/Documents/userlist.txt
do
echo $i
useradd $i
done

Last edited by Oblivionsmist; 10-22-2017 at 03:07 AM.
 
Old 10-22-2017, 03:42 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,090
Blog Entries: 3

Rep: Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665
Welcome.

You'll need a different delimiter in your input file between the user's name and the rest of the data. Also, you'll need to look at the options available for useradd. Lastly, it will help if you can wrap your script in [code] [/code] tags here so that indenting and other whitespace is preserved.

Code:
while read i; do
        echo $i;
        ...
        useradd ... ;
done < /home/Documents/user.list.txt
Which course or class is this for?

Last edited by Turbocapitalist; 10-22-2017 at 03:44 AM.
 
1 members found this post helpful.
Old 10-22-2017, 03:53 AM   #3
Oblivionsmist
LQ Newbie
 
Registered: Oct 2017
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks for the reply, i am doing an introductory course for Linux scripting
 
Old 10-22-2017, 03:57 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,090
Blog Entries: 3

Rep: Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665
Nice. Be sure to check the reference manuals frequently. They vary in quality but are worth getting familiar with, and that takes repeated exposure so check them often.

Code:
man useradd
man awk
man bash
That last one will be overwhelming no matter how many years you have been working with it. However, it is very useful to learn to navigate that monster.

There are also some very useful guides to check on as you go through your task:

http://mywiki.wooledge.org/BashPitfalls
http://mywiki.wooledge.org/BashFAQ
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send email to multiple users which are grep'ed from a text file vamshi krishna Linux - Newbie 2 07-03-2015 06:15 AM
[SOLVED] Add multiple users on linux via file. NerdGZ Linux - Newbie 3 07-30-2014 07:49 AM
LXer: Linux for Users: Text Entry and Other Widgets that Make GUI Shell Scripting Easy LXer Syndicated Linux News 0 06-24-2012 06:00 AM
Combine multiple one column text file into one text file with multiple colum khairilthegreat Linux - Newbie 7 11-23-2007 02:31 PM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 12:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration