forked from AbeTavarez/Python_DevOps_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyslog.py
More file actions
48 lines (36 loc) Β· 1.47 KB
/
Copy pathsyslog.py
File metadata and controls
48 lines (36 loc) Β· 1.47 KB
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
46
47
48
import re
def show_time_of_pid(line):
# how to do it in one group?
pattern = r'^([A-Za-z]+ \d \d+:\d+:\d+)'
result = re.search(pattern, line)
p2 = r'(\d{5})'
r2 = re.search(p2, line)
return '{} pid:{}'.format(result[1], r2[1]) pattern = r'^([A-Za-z]+ \d \d+:\d+:\d+)'
# pattern = r'^([A-Za-z]+ \d \d+:\d+:\d+) (\[\d+\])'
# result = re.search(pattern, line)
# print(type(result))
# return f'{result[1]}'
# When searching log files using regex, which regex statement will search for the alphanumeric word "IP" followed by one or more digits wrapped in parentheses using a capturing group?
#r"IP \((\d+)\)$"
#
# Jul 6 14:01:23 pid:29440
print(show_time_of_pid(
"Jul 6 14:01:23 computer.name CRON[29440]: USER (good_user)"))
# Jul 6 14:02:08 pid:29187
print(show_time_of_pid(
"Jul 6 14:02:08 computer.name jam_tag=psim[29187]: (UUID:006)"))
# Jul 6 14:02:09 pid:29187
print(show_time_of_pid(
"Jul 6 14:02:09 computer.name jam_tag=psim[29187]: (UUID:007)"))
# Jul 6 14:03:01 pid:29440
print(show_time_of_pid(
"Jul 6 14:03:01 computer.name CRON[29440]: USER (naughty_user)"))
# Jul 6 14:03:40 pid:29807
print(show_time_of_pid(
"Jul 6 14:03:40 computer.name cacheclient[29807]: start syncing from \"0xDEADBEEF\""))
# Jul 6 14:04:01 pid:29440
print(show_time_of_pid(
"Jul 6 14:04:01 computer.name CRON[29440]: USER (naughty_user)"))
# Jul 6 14:05:01 pid:29440
print(show_time_of_pid(
"Jul 6 14:05:01 computer.name CRON[29440]: USER (naughty_user)"))