Skip to content

Commit 85c5048

Browse files
committed
add: dmesg logging; improve: make logs based on extracted suffix for dmesg pairing with logcats on action.sh
This commit uses grep -oE to extract the log suffix "-2" (action.sh) or "2" (post-fs-data.sh) it allows the new dmesg logs to be paired with the corresponding log on the action script and also allow a simplification on post-fs-data.sh by checking if the last log is not the last before returning to the starting log (3) and if the initial log is existent to add 1 to the last log which defaults to 2 (1+1) if it doesn't contain a suffix (first log) while if the starting log is non existent or the last log was the finishing one before looping back (3) it will use no suffix to create the starting log Signed-off-by: TheSillyOk <priv.ld@proton.me>
1 parent f67ffbf commit 85c5048

2 files changed

Lines changed: 33 additions & 15 deletions

File tree

action.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ mkdir -p "$SAVE_FOLDER"
1313

1414
log "Selecting the latest debug log file..."
1515

16-
LATEST=$(ls -t "$SAVE_FOLDER"/DebugAssistant* | grep -v "-Redacted" | head -n 1)
17-
if [[ "$LATEST" == "" ]]; then
16+
LATEST_SUFFIX=$(basename $(ls -t "$SAVE_FOLDER/"DebugAssistant* | grep -v "-Redacted" | head -n 1) | grep -oE "(-[0-9]+)?")
17+
LATEST="DebugAssistant$LATEST_SUFFIX.log"
18+
if [[ ! -f "$SAVE_FOLDER/$LATEST" ]]; then
1819
log "[!] No debug logs found. Exiting..."
1920
sleep 4
2021
exit 1
2122
fi
2223

2324
NEW_LOG="$SAVE_FOLDER/DebugAssistant-Redacted.log"
25+
DMESG_LOG="$SAVE_FOLDER/DebugAssistant-DMESG$LATEST_SUFFIX.log"
2426

25-
log "Latest debug log selected: $(basename $LATEST)"
27+
log "Latest debug log selected: $LATEST"
2628

2729
log "Redacting sensitive information..."
2830

@@ -59,9 +61,11 @@ sed -E \
5961
\
6062
\
6163
\
62-
"$LATEST" > "$NEW_LOG"
64+
"$SAVE_FOLDER/$LATEST" > "$NEW_LOG"
6365

6466
log "Redacted logs in $NEW_LOG"
6567

6668
cp "$NEW_LOG" /sdcard/Download
67-
log "Copied redacted log to /sdcard/Download..."
69+
cp "$DMESG_LOG" /sdcard/Download
70+
log "Copied redacted log and matching dmesg to /sdcard/Download..."
71+
sleep 3

post-fs-data.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,47 @@
33
# A tool to collect extremely verbose debug log from the Android system.
44
# LICENSE: BSD 3-Clause by ThePedroo
55

6-
SAVE_FOLDER=/data/local/tmp/DebugAssistant
7-
6+
SAVE_FOLDER="/data/local/tmp/DebugAssistant"
87
mkdir -p "$SAVE_FOLDER"
98

10-
function prepare_file() {
9+
start_log() {
10+
local suffix="$1"
11+
12+
watch_logcat "$suffix"
13+
watch_dmesg "$suffix"
14+
}
15+
16+
prepare_file() {
1117
local file_path="$1"
1218

1319
rm "$file_path"
1420
touch "$file_path"
1521
chown shell:shell "$file_path"
1622
}
1723

18-
function watch_logcat() {
24+
watch_logcat() {
1925
local file_path="$SAVE_FOLDER/DebugAssistant$1.log"
2026
prepare_file "$file_path"
2127

2228
while [ ! ];do logcat;sleep 1;done > "$file_path" &
2329
}
2430

31+
watch_dmesg() {
32+
local file_path="$SAVE_FOLDER/DebugAssistant-DMESG$1.log"
33+
prepare_file "$file_path"
34+
35+
if dmesg --help 2>&1 | grep -q "\-w"; then
36+
dmesg -w > "$file_path" &
37+
else
38+
while [ ! ];do dmesg > "$file_path";sleep 1;done &
39+
fi
40+
}
2541

26-
LATEST=$(basename $(ls -t "$SAVE_FOLDER"/DebugAssistant*.log | grep -v "Redacted" | head -n 1))
27-
if [[ "$LATEST" == "DebugAssistant.log" ]]; then
28-
SUFFIX="-2"
29-
elif [[ "$LATEST" == "DebugAssistant-2.log" ]]; then
30-
SUFFIX="-3"
42+
LATEST_SUFFIX=$(basename $(ls -t "$SAVE_FOLDER"/DebugAssistant*.log | grep -v "Redacted" | head -n 1) | grep -oE "([0-9]+)?")
43+
if [[ -f "$SAVE_FOLDER/DebugAssistant.log" && "$LATEST_SUFFIX" != "3" ]]; then
44+
SUFFIX="-$(( ${LATEST_SUFFIX:-1} + 1 ))"
3145
else
3246
SUFFIX=""
3347
fi
3448

35-
watch_logcat "$SUFFIX"
49+
start_log "$SUFFIX"

0 commit comments

Comments
 (0)