Guest User

Untitled

a guest
Nov 27th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id();
  2.  
  3. #! / usr / bin / python
  4. # - * - coding: UTF-8 - * -
  5. import os, sys
  6. import signal, os, sys
  7. import MySQLdb
  8. conexion_mysql = MySQLdb.connect(host = '10.248.204.43', user = 'root', passwd = 'sahc', db = 'Biblioteca')
  9.  
  10. cur = conexion_mysql.cursor()
  11. consulta = ('SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id()')
  12. cur.execute(consulta)
  13. for row in cur.fetchall():
  14. resultado = row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]
  15. sql = "INSERT INTO prueba VALUES (" + str(row[0]) + "," + "'" + (row[1] or '') + "'" + "," + "'" + (row[2] or '') + "'" + "," + "'" + (row[3] or '') + "'" + "," + "'" + (row[4] or '') + "'" + "," + str(row[5]) + "," + "'" + (row[6] or '') + "'" + "," + "'" + (row[7] or '') + "'" + "," + "now()" + ")"
  16. cur.execute(sql)
  17. conexion_mysql.commit()
  18. print "Datos Guardados Exitosamente"
  19. if row[0] == row[0]:
  20. matar = "KILL " + str(row[0])
  21. cur.execute(matar)
  22. conexion_mysql.commit()
  23. print "Datos eliminados"
  24.  
  25. import pypyodbc
  26.  
  27. # Completar <<server>> <<user>> y <<passw>>
  28. conn = pypyodbc.connect("DRIVER={SQL Server};SERVER=<<server>>;DATABASE=master;UID=<<user>>;PWD=<<passw>>")
  29. cur = conn.cursor()
  30.  
  31. # Este es tu INSERT revisar compatibilidad MySql / MSSQL
  32. sql = "INSERT INTO prueba VALUES (" + str(row[0]) + "," + "'" + (row[1] or '') + "'" + "," + "'" + (row[2] or '') + "'" + "," + "'" + (row[3] or '') + "'" + "," + "'" + (row[4] or '') + "'" + "," + str(row[5]) + "," + "'" + (row[6] or '') + "'" + "," + "'" + (row[7] or '') + "'" + "," + "now()" + ")"
  33. cur.execute(sql)
  34. cur.commit()
  35.  
  36. # Cierro conexión
  37. conn.close()
  38.  
  39. #! / usr / bin / python
  40. # - * - coding: UTF-8 - * -
  41. import os, sys
  42. import signal, os, sys
  43. import MySQLdb #MySQL
  44. import pymssql #SQL server 2016
  45.  
  46. #Conexión a MySQL
  47. conexion_mysql = MySQLdb.connect(host = '10.248.204.43', user = 'root', passwd = 'sahc', db = 'Biblioteca')
  48.  
  49. #Conexión a SQL Server
  50. server = "AXPOS10"
  51. user = "santiago"
  52. password = "Python@Monitor"
  53. base = "StoragePython"
  54. conexion_sql = pymssql.connect(server, user, password, base)
  55.  
  56. cur = conexion_mysql.cursor() #Cursor de Mysql
  57. cur2 = conexion_sql.cursor() #Cursor de SQL Server
  58.  
  59. #Consulta a MySQL
  60. consulta = ('SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id()')
  61. cur.execute(consulta) #Ejecución de consulta MySQL apartir del for es ejecución a SQL Server y en el if se ejecuta el comando KILL en MySQL
  62. for row in cur.fetchall():
  63. resultado = row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]
  64. sql = "INSERT INTO LogKillProcesstMySQL VALUES (" + str(row[0]) + "," + "'" + (row[1] or '') + "'" + "," + "'" + (row[2] or '') + "'" + "," + "'" + (row[3] or '') + "'" + "," + "'" + (row[4] or '') + "'" + "," + str(row[5]) + "," + "'" + (row[6] or '') + "'" + "," + "'" + (row[7] or '') + "'" + "," + "GETDATE()" + ")"
  65. cur2.execute(sql) #Ejecución de insertado SQL Server
  66. conexion_sql.commit()
  67. print "Datos Guardados Exitosamente"
  68. if row[0] == row[0]:
  69. matar = "KILL " + str(row[0])
  70. cur.execute(matar)
  71. conexion_mysql.commit()
  72. print "Datos eliminados"
Add Comment
Please, Sign In to add comment