How to add users from text file into the unix system?











up vote
-1
down vote

favorite












I have a homework that require creating text file of users in unix and then reading each line of the file and actually adding them to the system?



How can this be done?
what i have done:



https://i.stack.imgur.com/G2LAK.png



however it's not working.










share|improve this question




















  • 2




    Homeworks are off topic here ;)
    – Kulfy
    Nov 22 at 12:08










  • Hint: you need to learn how to create a text files. What information about the user is there in the file? How to read file, a.k.a file handling? How to create new user through the command line?
    – Kulfy
    Nov 22 at 12:12










  • I thought so hard about this and still cant get how to change user (as a text) into an actual system user!
    – user895829
    Nov 22 at 12:16










  • Store into a variable and use that variable say $user
    – Kulfy
    Nov 22 at 12:22






  • 4




    I have seen other homework problems receive favorable responses - the difference is that the person asking the question has shown the work that they have already done, and is asking what they are doing wrong, rather than asking "how to do this". Can you amend your question with what you have already tried?
    – Charles Green
    Nov 22 at 16:42















up vote
-1
down vote

favorite












I have a homework that require creating text file of users in unix and then reading each line of the file and actually adding them to the system?



How can this be done?
what i have done:



https://i.stack.imgur.com/G2LAK.png



however it's not working.










share|improve this question




















  • 2




    Homeworks are off topic here ;)
    – Kulfy
    Nov 22 at 12:08










  • Hint: you need to learn how to create a text files. What information about the user is there in the file? How to read file, a.k.a file handling? How to create new user through the command line?
    – Kulfy
    Nov 22 at 12:12










  • I thought so hard about this and still cant get how to change user (as a text) into an actual system user!
    – user895829
    Nov 22 at 12:16










  • Store into a variable and use that variable say $user
    – Kulfy
    Nov 22 at 12:22






  • 4




    I have seen other homework problems receive favorable responses - the difference is that the person asking the question has shown the work that they have already done, and is asking what they are doing wrong, rather than asking "how to do this". Can you amend your question with what you have already tried?
    – Charles Green
    Nov 22 at 16:42













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have a homework that require creating text file of users in unix and then reading each line of the file and actually adding them to the system?



How can this be done?
what i have done:



https://i.stack.imgur.com/G2LAK.png



however it's not working.










share|improve this question















I have a homework that require creating text file of users in unix and then reading each line of the file and actually adding them to the system?



How can this be done?
what i have done:



https://i.stack.imgur.com/G2LAK.png



however it's not working.







server syslinux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 19:31

























asked Nov 22 at 12:08







user895829















  • 2




    Homeworks are off topic here ;)
    – Kulfy
    Nov 22 at 12:08










  • Hint: you need to learn how to create a text files. What information about the user is there in the file? How to read file, a.k.a file handling? How to create new user through the command line?
    – Kulfy
    Nov 22 at 12:12










  • I thought so hard about this and still cant get how to change user (as a text) into an actual system user!
    – user895829
    Nov 22 at 12:16










  • Store into a variable and use that variable say $user
    – Kulfy
    Nov 22 at 12:22






  • 4




    I have seen other homework problems receive favorable responses - the difference is that the person asking the question has shown the work that they have already done, and is asking what they are doing wrong, rather than asking "how to do this". Can you amend your question with what you have already tried?
    – Charles Green
    Nov 22 at 16:42














  • 2




    Homeworks are off topic here ;)
    – Kulfy
    Nov 22 at 12:08










  • Hint: you need to learn how to create a text files. What information about the user is there in the file? How to read file, a.k.a file handling? How to create new user through the command line?
    – Kulfy
    Nov 22 at 12:12










  • I thought so hard about this and still cant get how to change user (as a text) into an actual system user!
    – user895829
    Nov 22 at 12:16










  • Store into a variable and use that variable say $user
    – Kulfy
    Nov 22 at 12:22






  • 4




    I have seen other homework problems receive favorable responses - the difference is that the person asking the question has shown the work that they have already done, and is asking what they are doing wrong, rather than asking "how to do this". Can you amend your question with what you have already tried?
    – Charles Green
    Nov 22 at 16:42








2




2




Homeworks are off topic here ;)
– Kulfy
Nov 22 at 12:08




Homeworks are off topic here ;)
– Kulfy
Nov 22 at 12:08












Hint: you need to learn how to create a text files. What information about the user is there in the file? How to read file, a.k.a file handling? How to create new user through the command line?
– Kulfy
Nov 22 at 12:12




Hint: you need to learn how to create a text files. What information about the user is there in the file? How to read file, a.k.a file handling? How to create new user through the command line?
– Kulfy
Nov 22 at 12:12












I thought so hard about this and still cant get how to change user (as a text) into an actual system user!
– user895829
Nov 22 at 12:16




I thought so hard about this and still cant get how to change user (as a text) into an actual system user!
– user895829
Nov 22 at 12:16












Store into a variable and use that variable say $user
– Kulfy
Nov 22 at 12:22




Store into a variable and use that variable say $user
– Kulfy
Nov 22 at 12:22




4




4




I have seen other homework problems receive favorable responses - the difference is that the person asking the question has shown the work that they have already done, and is asking what they are doing wrong, rather than asking "how to do this". Can you amend your question with what you have already tried?
– Charles Green
Nov 22 at 16:42




I have seen other homework problems receive favorable responses - the difference is that the person asking the question has shown the work that they have already done, and is asking what they are doing wrong, rather than asking "how to do this". Can you amend your question with what you have already tried?
– Charles Green
Nov 22 at 16:42










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Create a file with name: text witch contains all users name.



for example my text file contents
usertemp



this is only one test user name.



Then create bash script file like this



run.sh



#!/bin/bash

while read line; do

useradd $line

done < text


Make the script run.sh runnable by type in terminal



chmod +x run.sh



At last run script with



./run.sh



Running above script may need root privileges.



sudo ./run.sh



Now these users cant log on because we have not assign any password to them.



[ToDO]




  1. Assign password for created list of users.

  2. Difference between using adduser and useradd, in this situation. see

  3. Read username, password from only one file, text.


[Related posts]




  1. https://askubuntu.com/a/1068448/678872


[Edit]




  • Remove redundant chmod 777 run.sh as wjandrea said on comment, its only make the script readable writable and executable for everyone see more


  • Use read command in script instead of more, to read line by line. I think its better in speed.







share|improve this answer



















  • 4




    Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
    – wjandrea
    Nov 22 at 20:06











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1095085%2fhow-to-add-users-from-text-file-into-the-unix-system%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Create a file with name: text witch contains all users name.



for example my text file contents
usertemp



this is only one test user name.



Then create bash script file like this



run.sh



#!/bin/bash

while read line; do

useradd $line

done < text


Make the script run.sh runnable by type in terminal



chmod +x run.sh



At last run script with



./run.sh



Running above script may need root privileges.



sudo ./run.sh



Now these users cant log on because we have not assign any password to them.



[ToDO]




  1. Assign password for created list of users.

  2. Difference between using adduser and useradd, in this situation. see

  3. Read username, password from only one file, text.


[Related posts]




  1. https://askubuntu.com/a/1068448/678872


[Edit]




  • Remove redundant chmod 777 run.sh as wjandrea said on comment, its only make the script readable writable and executable for everyone see more


  • Use read command in script instead of more, to read line by line. I think its better in speed.







share|improve this answer



















  • 4




    Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
    – wjandrea
    Nov 22 at 20:06















up vote
1
down vote



accepted










Create a file with name: text witch contains all users name.



for example my text file contents
usertemp



this is only one test user name.



Then create bash script file like this



run.sh



#!/bin/bash

while read line; do

useradd $line

done < text


Make the script run.sh runnable by type in terminal



chmod +x run.sh



At last run script with



./run.sh



Running above script may need root privileges.



sudo ./run.sh



Now these users cant log on because we have not assign any password to them.



[ToDO]




  1. Assign password for created list of users.

  2. Difference between using adduser and useradd, in this situation. see

  3. Read username, password from only one file, text.


[Related posts]




  1. https://askubuntu.com/a/1068448/678872


[Edit]




  • Remove redundant chmod 777 run.sh as wjandrea said on comment, its only make the script readable writable and executable for everyone see more


  • Use read command in script instead of more, to read line by line. I think its better in speed.







share|improve this answer



















  • 4




    Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
    – wjandrea
    Nov 22 at 20:06













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Create a file with name: text witch contains all users name.



for example my text file contents
usertemp



this is only one test user name.



Then create bash script file like this



run.sh



#!/bin/bash

while read line; do

useradd $line

done < text


Make the script run.sh runnable by type in terminal



chmod +x run.sh



At last run script with



./run.sh



Running above script may need root privileges.



sudo ./run.sh



Now these users cant log on because we have not assign any password to them.



[ToDO]




  1. Assign password for created list of users.

  2. Difference between using adduser and useradd, in this situation. see

  3. Read username, password from only one file, text.


[Related posts]




  1. https://askubuntu.com/a/1068448/678872


[Edit]




  • Remove redundant chmod 777 run.sh as wjandrea said on comment, its only make the script readable writable and executable for everyone see more


  • Use read command in script instead of more, to read line by line. I think its better in speed.







share|improve this answer














Create a file with name: text witch contains all users name.



for example my text file contents
usertemp



this is only one test user name.



Then create bash script file like this



run.sh



#!/bin/bash

while read line; do

useradd $line

done < text


Make the script run.sh runnable by type in terminal



chmod +x run.sh



At last run script with



./run.sh



Running above script may need root privileges.



sudo ./run.sh



Now these users cant log on because we have not assign any password to them.



[ToDO]




  1. Assign password for created list of users.

  2. Difference between using adduser and useradd, in this situation. see

  3. Read username, password from only one file, text.


[Related posts]




  1. https://askubuntu.com/a/1068448/678872


[Edit]




  • Remove redundant chmod 777 run.sh as wjandrea said on comment, its only make the script readable writable and executable for everyone see more


  • Use read command in script instead of more, to read line by line. I think its better in speed.








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 at 12:04

























answered Nov 22 at 13:55









EsmaeelE

1867




1867








  • 4




    Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
    – wjandrea
    Nov 22 at 20:06














  • 4




    Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
    – wjandrea
    Nov 22 at 20:06








4




4




Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
– wjandrea
Nov 22 at 20:06




Why are you using more instead of just reading the file? i.e. while read line; do ... done < text. Also running chmod 777 then chmod +x is redundant.
– wjandrea
Nov 22 at 20:06


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1095085%2fhow-to-add-users-from-text-file-into-the-unix-system%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ellipse (mathématiques)

Quarter-circle Tiles

Mont Emei