General idea, there are n sets of MC, to dump out data, n sets to compare, see whether the data is consistent, design to the same time dump problem, the server broke the clockwork command to the N MC,MC at the same time to dump the results back to the server side, the server side to compare these results
Server segment
#!/usr/bin/python
#coding: UTF8
Import socket
Import OS
Import threading
Import time
Import Sys
def work_1 (Ip,conn):
Global Should_stop
While True:
‘‘‘
If Should_stop:
Print "Should_stop"
Break
‘‘‘
Time.sleep (10)
Conn.send (IP)
CLIENT_DATA=CONN.RECV (1024)
Data1=client_data.split ("") [0]
Try
Data2=client_data.split ("") [1]
Except Indexerror, E:
Print "Should_stop set"
Should_stop = True
Bb=open ('/home/text.txt ', ' a ')
Bb.write (client_data+ ' \ n ')
Print Time.time (), Client_data
S=socket.socket (Socket.af_inet,socket. SOCK_STREAM)
S.setsockopt (socket. Sol_socket, SOCKET. SO_REUSEADDR, 1)
S.bind (' 10.13.144.224 ', 9999)
S.listen (10)
S.setblocking (0)
S.settimeout (10)
ip= ' 10.13.144.224 '
List_1=[]
Should_stop = False
While True:
If Should_stop:break
Try
Conn,addr=s.accept ()
Except Socket.timeout:
Continue
Print "Client timeout:", Conn.gettimeout ()
A=0
Aa=threading. Thread (target=work_1,args= (Ip,conn))
List_1.append (AA)
Print List_1
Aa.start ()
Print "Join"
For I in List_1:
I.join ()
print ' +++++ '
Cc=open ('/home/text.txt ', ' R ')
Cd=open ('/home/text1.txt ', ' W ')
Ca=cc.readlines ()
For II in CA:
If II = = ':
Break
Elif II = = ' \ n ':
Pass
Else
Cd.write (ii)
Cd.close ()
Cg=open ('/home/text1.txt ', ' R ')
Cf=cg.readlines ()
dict_1={}
For IIII in CF:
print ' OK '
Dict_1[iiii.split ("") [0]]=iiii.split ("") [1]
Print Dict_1
print int (Dict_1[dict_1.keys () [0]])-int (Dict_1[dict_1.keys () [1]])
Cz=open ('/home/text.txt ', ' W ')
Cz.truncate ()
Cy=open ('/home/text1.txt ', ' W ')
Cy.truncate ()
print ' exit '
Client break
#!/usr/bin/python
#coding: UTF8
Import socket
Import time
Import Telnetlib
def mem_status (Ip,port):
Print IP
Print Port
Tn=telnetlib. Telnet (Ip,port)
Tn.set_debuglevel (1)
Tn.write (' dump/data0/logs/b.log ' + ' \ n ')
Tn.write (' quit ' + ' \ n ')
Return ' OK '
def work_lines (file):
Print file
Open_file=open (file, ' R ')
Print Open_file
File_lines=open_file.readlines ()
Return File_lines
C=socket.socket (Socket.af_inet,socket. SOCK_STREAM)
C.connect (' 10.13.144.224 ', 9999)
File= '/data0/logs/b.log '
REC=C.RECV (1024)
If rec = = ' 10.13.144.224 ':
Return_value=mem_status (' 10.67.15.11 ', 22224)
Time.sleep (10)
If Return_value:
A=open ('/data0/logs/b.log ', ' R ')
File_lines=a.readlines ()
Over= ' 10.67.15.11 ' + ' +str (len (file_lines))
Print over
#over = ' 10.13.144.224 ', str (len (file_lines))
C.send (str (over))
This article is from the "Expect batch Sync data" blog, so be sure to keep this source http://4249964.blog.51cto.com/4239964/1557426
Scoket Multithreading Examples