用ADB 抓 mtk 平台的 log

MTK的eng 平台把mtk mobilelog 保存在目录:sdcard/mtklog/mobilelog/里

用bat脚本抓取log,log保存在bat所在的路径内,

例如:log脚本\Logs\Log_20161122162658\APLog_2010_0106_010742


@echo off
set current_path=%cd%
set my_d=%date:~,10%
set my_d=%my_d:-=%
set my_d=%my_d:/=%
set my_t=%time:~,8%
set my_t=%my_t::=%
set my_t=%my_t: =0%
set mydate=%my_d%%my_t%
echo 当前时间: %mydate%,路径: %current_path%
echo 等待adb连接。。。
adb wait-for-device
adb root
adb remount

rem rd /S /Q %current_path%\Log_Tmp
rem md %current_path%\Log_Tmp
md %current_path%\Logs\Log_%mydate%
set log_path=%current_path%\Logs\Log_%mydate%
set tmp_file=%log_path%\tmp.txt

adb shell ls sdcard/mtklog/mobilelog/ >%tmp_file%

setlocal ENABLEDELAYEDEXPANSION
echo 所有mobilelog列表,旧到新排序:
set mindex=1
set index=0
set j=0
for /f "delims=""" %%i in (%tmp_file%) do (
set /a j+=1
set /a index+=!mindex!
set con!j!=%%i
call set a=%%con!j!%%
set alllogs_!index!=!a!
echo !index!,!a!
set last_log=!a!
)
set num_all_logs=%index%
set num_logs=1
if %num_all_logs% GTR 10 (
	echo adb平台有超出10份log,无法处理
	pause>>nul
	goto CLEAN_REBOOT
)

set /p num_logs=请输入要抓的最新N份log(默认1份):
if %num_logs% GTR %num_all_logs% (
	echo 总共只有%num_all_logs%份log,不能抓取%num_logs%份
	set num_logs=%num_all_logs%
)

set /a num_pass_log=%num_all_logs% - %num_logs%
set /a index_end_log=%num_all_logs%
set /a index_start_log=%num_pass_log% + 1
rem echo index_start_log=%index_start_log%,num_pass_log=%num_pass_log%,index_end_log=%index_end_log%
echo 开始抓取最新的%num_logs%份log。。。
if %index_start_log% LEQ 1 if %index_end_log% GEQ 1 adb pull sdcard/mtklog/mobilelog/%alllogs_1%  %log_path%\%alllogs_1%
if %index_start_log% LEQ 2 if %index_end_log% GEQ 2 adb pull sdcard/mtklog/mobilelog/%alllogs_2%  %log_path%\%alllogs_2%
if %index_start_log% LEQ 3 if %index_end_log% GEQ 3 adb pull sdcard/mtklog/mobilelog/%alllogs_3%  %log_path%\%alllogs_3%
if %index_start_log% LEQ 4 if %index_end_log% GEQ 4 adb pull sdcard/mtklog/mobilelog/%alllogs_4%  %log_path%\%alllogs_4%
if %index_start_log% LEQ 5 if %index_end_log% GEQ 5 adb pull sdcard/mtklog/mobilelog/%alllogs_5%  %log_path%\%alllogs_5%
if %index_start_log% LEQ 6 if %index_end_log% GEQ 6 adb pull sdcard/mtklog/mobilelog/%alllogs_6%  %log_path%\%alllogs_6%
if %index_start_log% LEQ 7 if %index_end_log% GEQ 7 adb pull sdcard/mtklog/mobilelog/%alllogs_7%  %log_path%\%alllogs_7%
if %index_start_log% LEQ 8 if %index_end_log% GEQ 8 adb pull sdcard/mtklog/mobilelog/%alllogs_8%  %log_path%\%alllogs_8%
if %index_start_log% LEQ 9 if %index_end_log% GEQ 9 adb pull sdcard/mtklog/mobilelog/%alllogs_9%  %log_path%\%alllogs_9%
if %index_start_log% LEQ 10 if %index_end_log% GEQ 10 adb pull sdcard/mtklog/mobilelog/%alllogs_10%  %log_path%\%alllogs_10%
	echo 完成抓取最新的%num_logs%份log,从旧到新排序:
	if %index_start_log% LEQ 1 if %index_end_log% GEQ 1 echo 1,%alllogs_1%
	if %index_start_log% LEQ 2 if %index_end_log% GEQ 2 echo 2,%alllogs_2%
	if %index_start_log% LEQ 3 if %index_end_log% GEQ 3 echo 3,%alllogs_3%
	if %index_start_log% LEQ 4 if %index_end_log% GEQ 4 echo 4,%alllogs_4%
	if %index_start_log% LEQ 5 if %index_end_log% GEQ 5 echo 5,%alllogs_5%
	if %index_start_log% LEQ 6 if %index_end_log% GEQ 6 echo 6,%alllogs_6%
	if %index_start_log% LEQ 7 if %index_end_log% GEQ 7 echo 7,%alllogs_7%
	if %index_start_log% LEQ 8 if %index_end_log% GEQ 8 echo 8,%alllogs_8%
	if %index_start_log% LEQ 9 if %index_end_log% GEQ 9 echo 9,%alllogs_9%
	if %index_start_log% LEQ 10 if %index_end_log% GEQ 10 echo 10,%alllogs_10%
goto DONE

:CLEAN_REBOOT
echo =====================
echo 旧的5份log:
echo 1,%alllogs_1%
echo 2,%alllogs_2%
echo 3,%alllogs_3%
echo 4,%alllogs_4%
echo 5,%alllogs_5%
echo =====================
set /p num_logs=是否清除旧的前5份log?
set /p num_logs=确定清除?
set /p num_logs=再确定清除?
adb shell rm -rf sdcard/mtklog/mobilelog/%alllogs_1%
adb shell rm -rf sdcard/mtklog/mobilelog/%alllogs_2%
adb shell rm -rf sdcard/mtklog/mobilelog/%alllogs_3%
adb shell rm -rf sdcard/mtklog/mobilelog/%alllogs_4%
adb shell rm -rf sdcard/mtklog/mobilelog/%alllogs_5%
echo 完成清除5份log
goto DONE

:DONE
echo 完成抓取,任意键退出
%SystemRoot%\explorer.exe "%log_path%"
pause>>nul
exit


你可能感兴趣的:(Linux)