LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using the attached file as a "database" of users, develop an application that reads the users.txt file, and adds each one as a new user. Eac (https://www.linuxquestions.org/questions/linux-newbie-8/using-the-attached-file-as-a-database-of-users-develop-an-application-that-reads-the-users-txt-file-and-adds-each-one-as-a-new-user-eac-4175663883/)

abdy.r.khalafi@gmail.com 11-07-2019 08:55 PM

Using the attached file as a "database" of users, develop an application that reads the users.txt file, and adds each one as a new user. Eac
 
Using the attached file as a "database" of users, develop an application that reads the users.txt file, and adds each one as a new user. Each user must also have a password, though in the interest of brevity, they may all be assigned the same one. Provide me the source code and a copy of your system's /etc/passwd file.

accounts.txt includes 1. Pittman,Mckenzie,Sales
2. Donovan,Moriah,Accounting
3. Barnes,Gabriel,Sales
4. Monroe,Maximillian,Management
5. Maynard,Sylvia,Management
6. Mayer,Elise,Accounting
7. Reeves,Stephen,Production
8. Oneill,Sean,Sales
9. Jackson,Hanna,Management
10. Lee,Alani,Production
11. Golden,Ibrahim,Production
12. Tyrese,Todd,Production
Note: it is perfectly acceptable to "leverage" code from another source provided: 1) you understand what the example code is doing, and 2) you write it yourself. Remember to give attribution to any code you use that you didn't write.

TB0ne 11-07-2019 09:01 PM

Quote:

Originally Posted by abdy.r.khalafi@gmail.com (Post 6055396)
Using the attached file as a "database" of users, develop an application that reads the users.txt file, and adds each one as a new user. Each user must also have a password, though in the interest of brevity, they may all be assigned the same one. Provide me the source code and a copy of your system's /etc/passwd file.

accounts.txt includes 1. Pittman,Mckenzie,Sales
2. Donovan,Moriah,Accounting
3. Barnes,Gabriel,Sales
4. Monroe,Maximillian,Management
5. Maynard,Sylvia,Management
6. Mayer,Elise,Accounting
7. Reeves,Stephen,Production
8. Oneill,Sean,Sales
9. Jackson,Hanna,Management
10. Lee,Alani,Production
11. Golden,Ibrahim,Production
12. Tyrese,Todd,Production

Ok...how much credit do we get for doing your homework for you?

Read the LQ Rules about such things. Post reported.

Firerat 11-07-2019 09:03 PM

man useradd
man passwd

https://mywiki.wooledge.org/BashGuide

berndbausch 11-07-2019 09:38 PM

Quote:

Originally Posted by Firerat (Post 6055399)

Does the bash guide includes text processing? You will need tools like awk, sed, cut to process the account.txt file.

On RHEL/Centos, there is a newusers command, which may simplify the task (or not). Not sure if other distros have it.

Firerat 11-07-2019 10:55 PM

Quote:

Originally Posted by berndbausch (Post 6055404)
Does the bash guide includes text processing? You will need tools like awk, sed, cut to process the account.txt file.

On RHEL/Centos, there is a newusers command, which may simplify the task (or not). Not sure if other distros have it.

errm

Code:

while IFS=${IFS/#/,} read anumber surname forename department
do
  printf "%s %s's department is %s in uppercase for fun\n" \
    ${forename} \
    ${surname} \
    ${department^^}
done < account.txt

now, grep could be used to check username does not already exist
if so, tag ${surname:0:1} on the end

but it could be done without grep

upper lower case may need to be accounted for , I seem to remember having to patch things to get uppercase support, but that was years ago.

AnanthaP 11-08-2019 01:04 AM

Quote:

Provide me the source code and a copy of your system's /etc/passwd file.
Not only that, the instructor is actually asking for a copy of the /etc/passwd file.

HA HA.

At no cost, should the OP should send it.

A before and after wc -l for /etc/passwd should do to show that entries have been added..

Generally, don't send /etc/passwd and /etc/shadow under any condition. They contain the hashed password and other details of the user.

OK

Firerat 11-08-2019 01:18 AM

Quote:

Originally Posted by AnanthaP (Post 6055420)
A before and after wc -l for /etc/passwd should do to show that entries have been added..

and hope nothing else added anything since you last counted

better to grep ^username: /etc/passwd

and grep -c . /etc/passwd is better than wc -l
no need to mess about with cut

Edit:
had a thought
wc -l </etc/passwd
also means you don't have to use cut

but I also wondered why you wouldn't trust the exit status of useradd

berndbausch 11-08-2019 02:29 AM

Quote:

Originally Posted by AnanthaP (Post 6055420)

Generally, don't send /etc/passwd and /etc/shadow under any condition. They contain the hashed password and other details of the user.

Not a problem if this is a training system.

abdy.r.khalafi@gmail.com 11-08-2019 08:10 AM

Quote:

Originally Posted by TB0ne (Post 6055397)
Ok...how much credit do we get for doing your homework for you?

Read the LQ Rules about such things. Post reported.

Well he mentioned ---> Note: it is perfectly acceptable to "leverage" code from another source provided: 1) you understand what the example code is doing, and 2) you write it yourself. Remember to give attribution to any code you use that you didn't write.

dugan 11-08-2019 08:24 AM

To be clear: does the instructor just want these entries added to /etc/passwd?

rtmistler 11-08-2019 08:26 AM

Quote:

Originally Posted by abdy.r.khalafi@gmail.com (Post 6055512)
Well he mentioned ---> Note: it is perfectly acceptable to "leverage" code from another source provided: 1) you understand what the example code is doing, and 2) you write it yourself. Remember to give attribution to any code you use that you didn't write.

Just so you do understand from the LQ Rules:
  • Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
You have not shown us what you've tried or discussed where you have confusion, you've just posted the assignment and it appears to be verbatim.

Many LQ members are very much capable of completing this type of homework assignment, however it is your assignment and your fellow LQ members, who are all volunteers are not here to provide "on demand" answers. Please show some effort, or at least web search for some of these answers.

TB0ne 11-08-2019 08:55 AM

Quote:

Originally Posted by abdy.r.khalafi@gmail.com (Post 6055512)
Well he mentioned ---> Note: it is perfectly acceptable to "leverage" code from another source provided: 1) you understand what the example code is doing, and 2) you write it yourself. Remember to give attribution to any code you use that you didn't write.

Great! So then show us **YOUR EFFORTS**. We don't have to learn this assignment, you do.

What have you done/tried/researched in order to do this? Because as of now, you posted your homework question, and seem to be expecting us to just answer it for you.

AnanthaP 11-10-2019 10:13 AM

Quote:

Not a problem if this is a training system.
Not sure about that. Isn't it the tutor's job to instill good practices ? Or at least avoid bad practices?

Firerat 11-10-2019 11:07 AM

Quote:

Originally Posted by AnanthaP (Post 6056178)
Not sure about that. Isn't it the tutor's job to instill good practices ? Or at least avoid bad practices?

I wouldn't get too excited about it, there is such a thing as context.

I will also point out that windows XP is a poor choice of platform to be finger wagging over security issues from.


All times are GMT -5. The time now is 09:43 AM.