forked from openwrt-xiaomi/xmir-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_dmesg.py
58 lines (43 loc) · 1.36 KB
/
read_dmesg.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
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import platform
import xmir_base
import gateway
from gateway import die
gw = gateway.Gateway()
fn_old = 'outdir/dmesg_old.txt'
fn_local = 'outdir/dmesg.txt'
fn_remote = '/tmp/dmesg.txt'
if os.path.exists(fn_local):
if os.path.exists(fn_old):
os.remove(fn_old)
os.rename(fn_local, fn_old)
print("Send command...")
gw.run_cmd("dmesg > " + fn_remote)
print("File {} created!".format(fn_remote))
print("Downloading data to a computer...")
gw.download(fn_remote, fn_local)
gw.run_cmd("rm -f " + fn_remote)
with open(fn_local, "r") as file:
data = file.read()
with open(fn_local, "w") as file:
file.write(data)
print("Kernel logs written to file {}".format(fn_local))
fn_old = 'outdir/syslog_old.txt'
fn_local = 'outdir/syslog.txt'
fn_remote = '/tmp/syslog.txt'
if os.path.exists(fn_local):
if os.path.exists(fn_old):
os.remove(fn_old)
os.rename(fn_local, fn_old)
gw.run_cmd("cat /data/usr/log/messages /tmp/messages > " + fn_remote)
#gw.run_cmd("cat /proc/xiaoqiang/xq_syslog > " + fn_remote)
gw.download(fn_remote, fn_local)
gw.run_cmd("rm -f " + fn_remote)
with open(fn_local, "r") as file:
data = file.read()
with open(fn_local, "w") as file:
file.write(data)
print("System logs are written to a file {}".format(fn_local))