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
format
name:uid:gid:cl ass:change:expi re:gecos:home_d ir:shell:passwo rd
or in my case
userid::20::::u sername::sh:pas sword
Then I do an os.system('addu ser -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.
CODE
*************** *************** *************** *************** ******
#!/usr/local/bin/python
import MySQLdb
import os
db=MySQLdb.conn ect(db="challen ge")
c=db.cursor()
c.execute("""SE LECT userid, password, name from users where status is
null""")
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(aL ist[line]) + "\n")
f1.close
os.system('addu ser -f /home/sean/bin/users.test')
*************** *************** *************** *************** ****
Thanks in advance. 3 1218
"Amy G" <am*******@cox. net> writes:
[...] 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.
[...] os.system('addu ser -f /home/sean/bin/users.test')
[...]
You're not checking the exit status. Read the docs for os.system and
os.wait, and look at the commands module. Then add code to your
program to log details of any failures (the logging module in 2.3 is
useful here), so you can figure out what goes wrong.
John
"Amy G" <am*******@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(aL ist[line]) + "\n")
Just in case you hadn't noticed the shortcut here:
for userid, password, name in c:
f1.write("%s::2 0::::%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.
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***********@ botanicus.net> wrote in message
news:99******** *************** ***@posting.goo gle.com... "Amy G" <am*******@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(aL ist[line]) + "\n")
Just in case you hadn't noticed the shortcut here:
for userid, password, name in c: f1.write("%s::2 0::::%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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sims |
last post by:
Hi,
I have a field in my DB that saves the date/time as a integer.
I get the time on my server using the time() function.
now, moving away from php and looking at (My)SQL only.
If I use functions like DATE() or NOW(), I don't get a Unix value, (but
rather a formatted date).
So I cannot use those functions to check against my saved value.
|
by: Sandy Norton |
last post by:
Hi folks,
I have been mulling over an idea for a very simple python-based
personal document management system. The source of this possible
solution is the following typical problem:
I accumulate a lot of files (documents, archives, pdfs, images, etc.)
on a daily basis and storing them in a hierarchical file system is
simple but unsatisfactory:
|
by: Joshua D. Drake |
last post by:
Hello,
I think the below just about says it all:
http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg
Sincerely,
Joshua Drake
|
by: Jan Wieck |
last post by:
Dear community,
for some reason the post I sent yesterday night still did not show up on
the mailing lists. I have set up some links on the developers side under
http://developer.postgresql.org/~wieck/slony1.html
The concept will be the base for some of my work as a Software Engineer
here at Afilias USA INC. in the near future. Afilias is like many of you
in need of reliable and performant replication solutions for backup and
failover...
|
by: job |
last post by:
REQUEST FOR PROPOSAL
Overview
Our company is a mom & pop company seeking to capitalize its marketing
to our several thousand past customer base, as well as expand. We
currently sell mainly out-of-print and/or hard-to-find music CDs,
DVDs, video games and books via Ebay. We would like to utilize our
website for additional sales and customer support with less dependency
on Ebay. Other goals pertaining to the proposal will be disclosed...
| |
by: John Baker |
last post by:
Hi:
I am URGENTLY in need of some book or web site OR tool that will help me integrate a
relatively simple access application into a web page or pages. This is a time recording
system (by project), and I would be more than wiling to pull the updated database down
from the Host using FTP on a monthly basis. Its just that I need to understand how to set
it up on the web site itself. The Host supports SQL.
Any direction you can give would...
|
by: strawberry |
last post by:
In the function below, I'd like to extend the scope of the $table
variable such that, once assigned it would become available to other
parts of the function. I thought 'global $table;' would solve this but
it's clear that I'm misunderstanding $variable persistence. I posted a
similar enquiry over at alt.php.mysql, but I guess this is a more
appropriate forum because the problems I'm having relate to PHP.
Any help appreciated.
...
|
by: bill |
last post by:
I am about to start on a module that will accept a location from
a user, use Google geolocation services to get the lat/lon and
then compute the distance from the site visitor to about 100
kennels (could grow to 1000 eventually).
Once I have the distance I need to sort the kennels by distance
and present those within 500 miles.
Approach 1: read the kennel lat/lon from the mysql kennel record
compute the distance
|
by: Bob Jones |
last post by:
I have an odd business requirement and I think that the implementation
is not correct in the terms of OOP development. Any help on the
concepts would be very appreciated!
We currently have a custom Page object which is derived from the base
Page object. We also have custom controls that derive from a base
class that performs custom drawing and inherits from our own
IOurControl interface. There is also a special caching layer in the
mix...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |