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 11-07-2019, 08:55 PM   #1
abdy.r.khalafi@gmail.com
LQ Newbie
 
Registered: Oct 2019
Posts: 2

Rep: Reputation: Disabled
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.

Last edited by abdy.r.khalafi@gmail.com; 11-08-2019 at 07:56 AM.
 
Old 11-07-2019, 09:01 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,616

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by abdy.r.khalafi@gmail.com View Post
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.
 
Old 11-07-2019, 09:03 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
man useradd
man passwd

https://mywiki.wooledge.org/BashGuide
 
Old 11-07-2019, 09:38 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Firerat View Post
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.
 
Old 11-07-2019, 10:55 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by berndbausch View Post
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.
 
1 members found this post helpful.
Old 11-08-2019, 01:04 AM   #6
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
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
 
Old 11-08-2019, 01:18 AM   #7
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by AnanthaP View Post
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

Last edited by Firerat; 11-08-2019 at 01:32 AM.
 
1 members found this post helpful.
Old 11-08-2019, 02:29 AM   #8
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by AnanthaP View Post

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.
 
Old 11-08-2019, 08:10 AM   #9
abdy.r.khalafi@gmail.com
LQ Newbie
 
Registered: Oct 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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.
 
Old 11-08-2019, 08:24 AM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
To be clear: does the instructor just want these entries added to /etc/passwd?
 
Old 11-08-2019, 08:26 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by abdy.r.khalafi@gmail.com View Post
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.

Last edited by rtmistler; 11-08-2019 at 08:29 AM.
 
1 members found this post helpful.
Old 11-08-2019, 08:55 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,616

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by abdy.r.khalafi@gmail.com View Post
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.
 
Old 11-10-2019, 10:13 AM   #13
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
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?
 
Old 11-10-2019, 11:07 AM   #14
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by AnanthaP View Post
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.
 
1 members found this post helpful.
  


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
[SOLVED] sed 'G' file.txt adds two newlines for each empty line vincix Programming 7 01-08-2019 07:44 AM
Difference between buffered disk reads and cached reads? pinga123 Linux - Newbie 1 07-13-2011 11:40 AM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
Can't burn CDs in K3b using CUE files (EAC-created) MheAd Linux - Software 5 09-16-2007 06:42 PM
Which is the best language to develop a database using application tuxfood Linux - Newbie 2 12-18-2004 02:05 PM

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

All times are GMT -5. The time now is 11:58 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