-2

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.

  • 2
    Homeworks are off topic here ;) – Kulfy Nov 22 '18 at 12:08
  • I thought so hard about this and still cant get how to change user (as a text) into an actual system user! –  Nov 22 '18 at 12:16
  • This should be closed in favour of the duplicate referenced below: https://askubuntu.com/q/1068434/459652 –  Nov 22 '18 at 15:07
  • 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 '18 at 16:42
  • i must apologize but english is not my first language and things might have been understood wrongly. –  Nov 22 '18 at 18:45
  • Please don't post pictures of text. Instead, copy the text, [edit] it into your post, and use the formatting tools like code formatting to make it look nice. – wjandrea Nov 22 '18 at 19:49
  • Ubuntu is not Unix, and Unix is off-topic here. If that's just a misunderstanding or typo, please [edit] the question to fix it. But if you are actually asking about Unix, please ask on Unix & Linux instead. – wjandrea Nov 22 '18 at 19:56

1 Answers1

1

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.

EsmaeelE
  • 337
  • 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 '18 at 20:06