Adding newusers to Unix system from mysql data (Better Approach)

Amy G amy-g-art at cox.net
Sat Dec 27 13:05:17 EST 2003


Thank you very much... it was indeed f1.close() that needed fixing.  Program
works flawlessly.

And thanks for the shortcut, that is a good one.


"David M. Wilson" <dw-google.com at botanicus.net> wrote in message
news:99dce321.0312270514.53ebf23d at posting.google.com...
> "Amy G" <amy-g-art at cox.net> wrote...
>
> > My problem is this...  It writes the data file without problem.  But,
the
> > os.system... does not necessarily work to add a new user.  By 'not
> > necessarily' I mean that it works some of the time, but not all of the
time.
> > If I run the program and it does not work, I can simple type 'adduser -f
> > <filepath>' at the command line and it works no problem.  Any ideas what
> > could be causing this.
>
> Have you tested adduser seperately? I can't see any problem with your
> code, suggesting it may be adduser.
>
>
> > for line in c:
> >     userid, password, name = line
>
> You can do inline tuple unpack:
>
>   for userid, password, name in c:
>
>
> >     aList.append("%s::20::::%s::sh:%s" %(userid, name, password))
> >
> > f1=open('/home/sean/bin/users.test', 'w')
> > for line in range(len(aList)):
> >     f1.write(str(aList[line]) + "\n")
>
> Just in case you hadn't noticed the shortcut here:
>
>    for userid, password, name in c:
>       f1.write("%s::20::::%s::sh:%s\n" %(userid, name, password))
>
>
> > f1.close
>
> Ahah! Where are the parenthesis? :)  Your file is probably not getting
> flushed to disk:
>
>    f1.close()
>
>
> David.






More information about the Python-list mailing list