und entsprechende bash scripte startet oder Kommandos direkt absetzt. Das Script
funktioniert, allerdings führt es auf meinem PIII 900MHz als Testmaschine zu einer Systemauslastung von ca. 78% .
Vermutlich sind meine Aufrufe von os.system Schuld daran. Allerdings hab ich es bisher noch
nicht hinbekommen zu lernnen, wie man es richtig macht. Kann mir mal jemand an diesem Script
demonstrieren, wie man das elegant löst?
Vielen Dank
André
Code: Alles auswählen
#!/usr/bin/python
import os
import MySQLdb
import string
import time
conffile = open("/etc/cbwebgui/cbconnect.conf","r")
for line in conffile:
confentry = line.split("=")
if confentry[0] == "dbhost":
dbhost = confentry[1]
elif confentry[0] == "dbuser":
dbuser = confentry[1]
elif confentry[0] == "dbpasswd":
dbpasswd = confentry[1]
elif confentry[0] == "dbname":
dbname = confentry[1]
conffile.close()
connection = MySQLdb.connect(dbhost[0:-1],dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1])
cursor = connection.cursor()
while True:
# get the next job
cursor.execute("SELECT id, command, argument, timestamp FROM jobs_current ORDER BY timestamp LIMIT 1")
res = cursor.fetchone()
if res != None:
# There is a job to do and here are the params
job_id = res[0]
job_command = res[1]
job_argument = res[2]
job_timestamp = res[3]
# seperate commands
if job_command == "restart":
# seperate restart arguments
if job_argument == "now":
os.system("asterisk -rx \"restart now\"")
elif job_argument == "gracefully":
os.system("asterisk -rx \"restart gracefully\"")
elif job_command == "reload":
# seperate reload arguments
if job_argument == "all":
os.system("asterisk -rx reload")
elif job_argument == "dialplan":
os.system("asterisk -rx \"dialplan reload\"")
elif job_argument == "sip":
os.system("asterisk -rx \"sip reload\"")
elif job_command == "write":
# seperate write arguments execute the related script
if job_argument == "extensions":
os.system("wextensions %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
elif job_argument == "sip":
os.system("wsip %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
elif job_argument == "queues":
os.system("wqueues %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
elif job_argument == "voicemail":
os.system("wvoicemail %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
elif job_argument == "agents":
os.system("wagents %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
elif job_argument == "meetme":
os.system("wmeetme %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
elif job_argument == "manager":
os.system("wmanager %s %s %s" % (dbuser[0:-1],dbpasswd[0:-1],dbname[0:-1]))
# delete last entry and enter values into jobs_done
cursor.execute("DELETE FROM jobs_current WHERE id='%s'" % job_id)
# cursor.execute("INSERT INTO `callbuntu`.`jobs_done` (id, job_id, timestamp, command, argument) VALUES (NULL, %s, %s, %s, %s)" % (job_id, job_timestamp, job_command, job_argument) )
time.sleep(1)