hey all,
I have this script : (see below) it looks in a db for cpid (unique identifier) and gets the rest of the data out of my db, and creates then a user in a hosting platform, but now to finish the script I need to add to the end that if the response of the "s.execute" is "SUCCESS" that it needs to delete the cpid from the database where it has taken it (cursor) anyone who can help me?
#!/usr/bin/env python
#Import Modules
import MySQLdb
import ssh
#Make connection
conn = MySQLdb.connect (host = "192.168.1.1",
user = "user",
passwd = "password",
db = "mydb")
# Create a cursor
cursor = conn.cursor ()
cursor2 = conn.cursor ()
# Run the query
cursor.execute ("SELECT * FROM hostingcreateq")
task = cursor.fetchall()
for row in cursor:
cpid = row[0]
cursor2.execute ("SELECT client_company, client_fname, client_lname, username, password, client_phone1, client_phone2, client_email, client_address, client_city, client_zip, client_country, pack_id, server FROM client_info, account_details, client_package WHERE client_info.client_id = client_package.cp_id AND account_details.cp_id = client_package.cp_id AND client_package.cp_id = %s", (cpid))
# Fetch the data
clientid = cursor2.fetchone ()
#print clientid
for row in cursor2:
cname = row[0]
name0 = row[1]
name1 = row[2]
uname = row[3]
paswd = row[4]
cphon = row[5]
cfaxe = row[6]
cemai = row[7]
caddr = row[8]
ccity = row[9]
czipe = row[10]
ccoun = row[11]
packi = row[12]
serve = row[13]
name = name0 + " " + name1
# Make packi a string
packi = str(packi)
#Make a dictionary
d = {"162": "webconnect-lite", "163": "webconnect", "164": "webconnect-plus", "165": "webconnect-pro", "40": "webconnect-lite"};hosti = d.get(packi, packi)
#SSH connection
s = ssh.Connection(host = serve)
#Check psa info
create = ('/usr/local/psa/bin/client --create "'+uname+'" -company "'+cname+'" -name "'+name+'" -passwd "'+paswd+'" -email "'+cemai+'" -addr "'+caddr+'" -city "'+ccity+'" -zip "'+czipe+'" -country "'+ccoun+'" -template "'+hosti+'"')
#info = s.execute('/usr/local/psa/bin/client --create "'+uname+'" -company "'+cname+'" -name "'+name+'" -passwd "'+paswd+'" -email "'+cemai+'" -addr "'+caddr+'" -city "'+ccity+'" -zip "'+czipe+'" -country "'+ccoun+'" -template "'+hosti+'"')
print create
#close the ssh
s.close()
# close the cursor
cursor.close ()
cursor2.close ()
conn.close ()