Linux Beginner - Help Needed

adams_aderrine

New Member
Joined
Mar 19, 2021
Messages
4
Reaction score
2
Credits
30
CSV FILE FORMAT IS
GEORGE,CHADWICK,01/03/63,Year 1
DEREK,COLEMAN,08/08/75,Year 2
PETER,DAIGNEAULT,02/03/68,Year 1

How to create a bash script to perform the below steps
Students taking 1st year courses (100-level) should have user ids starting at 1000. So in the /etc/passwd file for user jstone something like eg: jstone:x:1028:1002:Stone,John:/home/jstone:/bin/bash
Students taking 2nd year courses (200-level) should have user ids starting at 2000
 
Last edited:


This looks suspiciously like a homework question.

So, show us your work. Show us how far you've come and then explain where you're stuck.
 
Hi Jas,

I figured out everything except the iteration to set the year1 students uid starting from 1000 and year2 uid starting from 2000. Any help is much appreciated..
 
Last edited:
I'm otherwise occupied. We've got a scripting guru, but I'm not sure what time he's got. I'll ping him and see if he's got time to get you on to your next step.

@JasKinasis

Also, you may want to see this site:

 
I want to know whether am in correct path..
Not quite. There are a number of things I can see that don’t look right to me.
I don’t have time to look at it properly right no I’ll take a more in depth look at it tomorrow. But I can give you a run-down of the most obvious problems that I can see!

1. You don’t need to be using more file.csv | etc.. to create values for your name,lname,username and fname variables.
Not only do you not need to, it’s also incorrect!
Process the values of the variables you read in from the .csv file to generate those other variables for each user instead.

2. Your user creation code also looks suspicious. It looks like you’re attempting to give everybody in year 1 the user ID 1000 and everybody in year 2 the user ID 2000.
You might need to consider using a variable to keep track of the next available user ID for each year-group.
So the first user in year 1 gets UID 1000, the second gets UID 1001. Likewise for people in year 2. First one gets 2000, the next 2001 etc. etc.
Each time a user ID has been assigned to a member of one of the years, increment the variable storing the next ID for that year.

But, as a concession - I must admit I’m a little rusty with the exact behaviour of the useradd command. It is possible that it might allow you to pass in a minimal user ID and it will assign one that is higher if the mini unmask one is already taken..... so that part of your code might be ok.... I’m not 100% sure. But I’ll take a good look at the documentation for useradd when I look at this again and will get back to you on this!

3. You haven’t generated a password for each user, as specified in your spec/brief.

I hope this helps!
 
Not quite. There are a number of things I can see that don’t look right to me.
I don’t have time to look at it properly right no I’ll take a more in depth look at it tomorrow. But I can give you a run-down of the most obvious problems that I can see!

1. You don’t need to be using more file.csv | etc.. to create values for your name,lname,username and fname variables.
Not only do you not need to, it’s also incorrect!
Process the values of the variables you read in from the .csv file to generate those other variables for each user instead.

2. Your user creation code also looks suspicious. It looks like you’re attempting to give everybody in year 1 the user ID 1000 and everybody in year 2 the user ID 2000.
You might need to consider using a variable to keep track of the next available user ID for each year-group.
So the first user in year 1 gets UID 1000, the second gets UID 1001. Likewise for people in year 2. First one gets 2000, the next 2001 etc. etc.
Each time a user ID has been assigned to a member of one of the years, increment the variable storing the next ID for that year.

But, as a concession - I must admit I’m a little rusty with the exact behaviour of the useradd command. It is possible that it might allow you to pass in a minimal user ID and it will assign one that is higher if the mini unmask one is already taken..... so that part of your code might be ok.... I’m not 100% sure. But I’ll take a good look at the documentation for useradd when I look at this again and will get back to you on this!

3. You haven’t generated a password for each user, as specified in your spec/brief.

I hope this helps!
 
Last edited:

Members online


Latest posts

Top