[K12OSN] user account scripts

Ray Garza ray at mission.lib.tx.us
Tue Jan 9 14:50:30 UTC 2007


Hi Robert,

I tried your python script below on my home PC and it worked. But, when I try 
it on my work PC it doesn't. I get an error message as follows:

sys:1: DeprecationWarning: Non-ASCII character '\xc2' in file import_os on 
line 7, but no encoding declared; see 
http://www.python.org/peps/pep-0263.html for details
  File "import_os", line 7
        userinfo=i.split()
    ^
SyntaxError: invalid syntax

I'm using Python version 2.4.4 at work and the box I really want it on is 
using version 2.3.4.

On the 2.3.4 box I also get the same error message.

Ray

On Thursday 04 January 2007 18:19, Robert Arkiletian wrote:
> 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>





More information about the K12OSN mailing list