0

So recently I got myself a raspberry pi and I have been learning python and what not and I want to create a user from a text file but on the raspberry pi it's different with the raspberry pi you need to provide more than just a password and a user group you need all of this stuff

Enter the new value, or press ENTER for the default
Full Name []: something
Room Number []: 123
Work Phone []: 123
Home Phone []: 123
Other []: 123

How would I be able to do all of this from a text file, I am completely new to Linux scripting and that kind of stuff so I haven't really tried much other than the stuff that I have seen online but none of it works because the "raspbian" OS is a little different then most but here's just the script that i'm working with

sudo adduser --disabled-password random1

I know it's nothing but that will make the account so I don't need a password and then it takes me to the part where I need to put in the stuff above, if this is possible can you guys help me? Thanks!

5
  • So, you want a python script which will accept user input to then create a user of sorts? Commented Aug 4, 2015 at 15:36
  • Basically yeah I left that out so you guys would think its just from a text file with it technically is but I have already programmed a python script to get data from a webserver and put it into a text files and now I just want it so I can use a linux script or something to create a user from the file. Commented Aug 4, 2015 at 15:39
  • 1
    im a fan of putting things in JSON notation when storing it in files, but depending on how you save the text files, you can just read from it and then run something like: os.system(command); Commented Aug 4, 2015 at 15:55
  • Its a good idea but im just looking for a way to do this with a linux command Commented Aug 4, 2015 at 16:03
  • im a fan of running a script file or command which would run other files, so i would just execute the user creation within the realm of python since thats where all that data is coming from anyways. Commented Aug 4, 2015 at 16:22

1 Answer 1

2

There is adduser and then there's useradd (ouch).

The first is a perl script that's pretty interactive. The 2nd is great for doing stuff non-interactively. Simply provide all the appropriate options.

You can also then optionally call chfn which is the thing talking about room numbers and stuff no one uses. So minimally:

sudo useradd user1
sudo chfn -f 'full name' -h 'home phone' -o 'other stuff' -r 'room num' user1
Sign up to request clarification or add additional context in comments.

2 Comments

Could you explain what you did a little better though?? So I could understand what your doing like you use -f and -f what are those for? and why are you using them. Thanks.
@BSD_ If you do man chfn and man useradd it explains what all the possible arguments are and what values they can take.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.