Click here to Skip to main content
15,914,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, everybody
First of all, I'd like to say thank you to all of you for the forum (admins, users...), it's a really valuable resource for a lot a people, including me.
I don't know if this is the right place where to ask this, my question is about my homework. If it's not, please, could an admin move it to its right place?... I'm a bit confused with an exercise, so if anybody can point me in the right direction (Or give me the answer) I'll be really gratefull:

Given a text file called users.txt with this info inside:

Adam:2299:/home/store ;

John:8855:/home/accounts ;

Lisa:7744:/home/secondstore ;

Mary:6677:/home/address ;

The script should create an user using the first word of each line, the second word of each line will be used as password, and the third one as the home directory. The internal field separator is :

I can only use awk or shellscripting for the exercise. The teacher pointed that one of the posible solutions includes the SYSTEM command used inside AWK...but there are other solutions using only shellscripting.

I'm trying with (as root)
JavaScript
$ awk -F ':| ' '{ print("adduser --home", $3, $1"; echo", $2 " | passwd", $1) | "/bin/bash" }' users.txt

I don't know why it doesn't work

Any hint, any suggestion of other way of doing this or any help will be very apreciated
thanks
Posted
Updated 20-May-14 4:11am
v2
Comments
Richard MacCutchan 20-May-14 10:16am    
Start by using only the first part of the script (the awk command) to see that it prints out the correct information for each entry in the file. Then try adding the next parts of the pipeline one at a time until you see where the error occurs. Looking at what you have, I dont think those pipeline symbols are in the correct place, I would suggest you check your course notes for both pipelines, and the awk command.
txernobill 20-May-14 10:37am    
Thanks for your time & help, Richard, I'm gonna check that right now... I'm starting to think there shoul be an easier way to do this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900