forked from tuxknight/routingService
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.py
executable file
·45 lines (32 loc) · 865 Bytes
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
from subprocess import PIPE
from subprocess import Popen
class BaseMService(object):
def __init__(self):
pass
def read(self):
pass
def deal_with(self):
pass
def write(self):
pass
class MService(BaseMService):
def __init__(self):
self.data = ""
self.result = ""
def read(self, filename, lines):
self.data = Popen(['tail', '-n%d' % 5, filename],
stdout=PIPE).communicate()[0]
def deal_with(self):
if self.data:
self.result = self.data.upper()
else:
return 1
def write(self):
if self.result:
print(self.result.rstrip("\n"))
if __name__ == "__main__":
service = MService()
service.read("/var/log/syslog", 5)
service.deal_with()
service.write()