[K12OSN] user account scripts

Robert Arkiletian robark at gmail.com
Fri Jan 5 00:19:10 UTC 2007


On 1/4/07, Ray Garza <ray at mission.lib.tx.us> wrote:
> Hello Script Gurus,
>
> Anyone know how to create user accounts from a text file using scripts?
>
> Example:
>
> user_accounts.txt
> "username1","password"
> "username2","password"
> "username3","password"
> "username4","password"
>
> convert that list into users on a local machine

well here is one that works without the "," between the username and
password and no quotes around the strings.


#!/usr/bin/python
import os

f=file('/home/ray/user_accounts.txt','r')
for i in f:
    userinfo=i.split()
    os.system("/usr/sbin/useradd -g users -n "+userinfo[0])
    #check man page for useradd to customize as needed
    os.system("echo " +userinfo[1]+" | /usr/bin/passwd "+
userinfo[0]+" --stdin")
f.close

I haven't really tested it properly so use it at your own risk.

>
> Better yet I need to convert a dbase file of usernames and passwords into
> valid local user accounts. I can convert the dbase file to other formats if
> that helps.
>
> Thanks
>
> Ray
>
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>
>


-- 
Robert Arkiletian
Eric Hamber Secondary, Vancouver, Canada
Fl_TeacherTool http://www3.telus.net/public/robark/Fl_TeacherTool/
C++ GUI tutorial http://www3.telus.net/public/robark/




More information about the K12OSN mailing list