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

Amy G amy-g-art at
Sat Dec 27 02:13:50 CET 2003

I am writing a simple Python program that will read in data from a database
(userid, password, username).  It will then store the data in a file in the


or in my case


Then I do an os.system('adduser -f <filepath>')

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.


import MySQLdb
import os

c.execute("""SELECT userid, password, name from users where status is
aList = []

for line in c:
    userid, password, name = line
    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")

os.system('adduser -f /home/sean/bin/users.test')


Thanks in advance.

More information about the Python-list mailing list