ADD BMC工具脚本

This commit is contained in:
leimingsheng 2025-06-04 15:27:45 +08:00
parent 023aa38673
commit 9b5d4a77d9
4 changed files with 262 additions and 19 deletions

@ -0,0 +1,38 @@
#!/bin/bash
BMC_IP=$1
BMC_USER=$2
BMC_PW=$3
BMC_INFO="${BMC_USER}:${BMC_PW}"
if [ $# -lt 3 ];then
echo "Script Usage:"
echo " ./Outband_Collect_OneKeyLog.sh <BMC_IP> <BMC_USERNAME> <BMC_PASSWORD>"
exit 0
fi
# Get BoardSN
BoardSN=`ipmitool -H ${BMC_IP} -I lanplus -U ${BMC_USER} -P ${BMC_PW} fru print | grep "Board Serial" | awk '{print $4}'`
if [ "${BoardSN}" = "" ];then
echo "Error: Can't Get BoardSN, please check network connection or user&password !"
exit 1
fi
time=`date "+%Y-%m-%dT%H:%M:%S"`
LOG_FILENAME="Product_${BoardSN}_${time}.tar.gz"
# Post message to BMC to collect all log
echo -e "\n Step 1. Post Collect all log to BMC"
curl -k -u $BMC_INFO -X POST -H "Content-Length: 0" https://${BMC_IP}/redfish/v1/Managers/1/LogServices/Actions/public/CollectAllLog
# Wait 60 seconds to Complete
echo -e "\n Waiting 150 seconds for collect all log ..."
sleep 150
# Download Onekeylog
echo -e "\n Step 2. Download Onekeylog"
curl -k -u $BMC_INFO -X POST -H "Content-Length: 0" https://${BMC_IP}/redfish/v1/Managers/1/LogServices/Actions/public/DownloadAllLog --output $LOG_FILENAME
# Complete
echo -e "\n Complete Download Onekeylog"

@ -0,0 +1,86 @@
@echo off
setlocal
:: Param Check
if "%1"=="" goto :USAGE
if "%2"=="" goto :USAGE
if "%3"=="" goto :USAGE
:: ==== Script will start here
::echo Command Infomation
::echo BMC_IP: %1
::echo USER: %2
::echo PASSWORD: %3
set "BMC_IP=%1"
set "USER=%2"
set "PASSWORD=%3"
set "BMC_INFO=%USER%:%PASSWORD%"
set "redfish_fru_result=%CD%\fru_info.json"
:: Step0. Get BMC SN
echo __________
echo Opertion 1 : Check Network Connection with BMC...
curl -k -u %BMC_INFO% -X GET "https://%BMC_IP%/redfish/v1/Systems/1/public/FRU" > %redfish_fru_result%
if %ERRORLEVEL% neq 0 (
echo Connect to BMC Failed
exit /b 1
)
for /f "delims=" %%a in ('
powershell -command "$json = Get-Content -Path '%redfish_fru_result%' -Raw | ConvertFrom-Json; $json.'board'.'Board Serial'"
') do set "value=%%a"
set "BoardSN=%value%"
:: Setp1. Get local time stamp
set "dt=%DATE% %TIME%"
for /f "tokens=2 delims==" %%a in ('wmic OS get LocalDateTime /value') do set "dt=%%a"
set "year=%dt:~0,4%"
set "month=%dt:~4,2%"
set "day=%dt:~6,2%"
set "hour=%dt:~8,2%"
set "minute=%dt:~10,2%"
set "second=%dt:~12,2%"
set "timestamp=%year%%month%%day%T%hour%%minute%%second%"
::echo TimeStamp: %timestamp%
set "LogFile=%CD%\Product_%BoardSN%_%timestamp%.tar.gz"
:: Step2. Post Collect Onekeylog Request to BMC by redfish
echo __________
echo Opertion 2 : Post Request to BMC...
curl -k -u %BMC_INFO% -X POST -H "Content-Length: 0" "https://%BMC_IP%/redfish/v1/Managers/1/LogServices/Actions/public/CollectAllLog"
if %ERRORLEVEL% neq 0 (
echo Post Request Error
exit /b 1
)
:: Step3. Wait 150s to Complete Collect
echo __________
echo Opertion 3 : Wait 150s for bmc to collect onekeylog...
timeout /t 150 /nobreak
:: Step4. Download Onekeylog
echo __________
echo Opertion 4 : Download onekeylog now ...
curl -k -u %BMC_INFO% -X POST -H "Content-Length: 0" "https://%BMC_IP%/redfish/v1/Managers/1/LogServices/Actions/public/DownloadAllLog" --output %LogFile%
if %ERRORLEVEL% neq 0 (
echo Download Onekeylog Error
exit /b 1
)
:: === Complete
echo __________
echo Opertion 5 : Success Download Onekeylog
echo Onekeylog Path: %LogFile%
goto :END
:USAGE
echo Invalid command format
echo Script Format : CollectOnekeylog.bat [bmc ip] [username] [password]
:END
endlocal

@ -0,0 +1,114 @@
#!/bin/sh
# ADC Base Address 0x1e6e 9000
# Channel0 & Channel 1 0x10
# Channel2 & Channel 3 0x14
# Channel4 & Channel 5 0x18
# Channel6 & Channel 7 0x1c
# Channel8 & Channel 9 0x20
# Channel10 & Channel 11 0x24
# Channel12 & Channel 13 0x28
# Channel14 & Channel 15 0x2c
# volt = ((data+1.0) /1024) *1.8; //ADC calculation formular
# volt *= resist; /* based on the hardware resistance added*/
Board_Desc="Common_Board"
Low_Position=0
High_Position=1
# ---------------------------------------------------------------
# Resist List
# ---------------------------------------------------------------
Channel00_resist=1
Channel01_resist=1
Channel02_resist=1
Channel03_resist=1
Channel04_resist=1
Channel05_resist=1
Channel06_resist=1
Channel07_resist=1
Channel08_resist=1
Channel09_resist=1
Channel10_resist=1
Channel11_resist=1
Channel12_resist=1
Channel13_resist=1
Channel14_resist=1
Channel15_resist=1
# ---------------------------------------------------------------
# Channel Name
# ---------------------------------------------------------------
Channel00_name="Channel00_Volt"
Channel01_name="Channel01_Volt"
Channel02_name="Channel02_Volt"
Channel03_name="Channel03_Volt"
Channel04_name="Channel04_Volt"
Channel05_name="Channel05_Volt"
Channel06_name="Channel06_Volt"
Channel07_name="Channel07_Volt"
Channel08_name="Channel08_Volt"
Channel09_name="Channel09_Volt"
Channel10_name="Channel10_Volt"
Channel11_name="Channel11_Volt"
Channel12_name="Channel12_Volt"
Channel13_name="Channel13_Volt"
Channel14_name="Channel14_Volt"
Channel15_name="Channel15_Volt"
# ---------------------------------------------------------------
# Function Define
# ---------------------------------------------------------------
# @Param1 ChannelNumber
# @Param2 ChannelRegOffset
# @Param3 Pos Flag
# @Param4 ChannelName
# @Param5 ChannelResist
read_channel_and_convert(){
RegAddr=0x1e6e90$2
# echo "RegAddr=${RegAddr}"
res=`devmem ${RegAddr} 32`
# echo $res
if [ $3 = $Low_Position ];then
ex=$(echo ${res} | cut -c 8)
h=$(echo ${res} | cut -c 9)
l=$(echo ${res} | cut -c 10)
hex_raw=${ex}${h}${l}
else
ex=$(echo ${res} | cut -c 4)
h=$(echo ${res} | cut -c 5)
l=$(echo ${res} | cut -c 6)
hex_raw=${ex}${h}${l}
fi
# Convert hex raw data to sensor value
dec_raw=$(echo "ibase=16; ${hex_raw}" | bc)
volt=$(echo "scale=4; ((${dec_raw} + 1.0) / 1024) * 1.8 * ${5} " | bc)
format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }')
# Output result
echo "Channel$1 | $4 : ${format_volt}V"
}
# ---------------------------------------------------------------
# Main
# ---------------------------------------------------------------
echo "Board Name : ${Board_Desc}"
read_channel_and_convert "00" "10" ${Low_Position} "${Channel00_name}" "${Channel00_resist}"
read_channel_and_convert "01" "10" ${High_Position} "${Channel01_name}" "${Channel01_resist}"
read_channel_and_convert "02" "14" ${Low_Position} "${Channel02_name}" "${Channel02_resist}"
read_channel_and_convert "03" "14" ${High_Position} "${Channel03_name}" "${Channel03_resist}"
read_channel_and_convert "04" "18" ${Low_Position} "${Channel04_name}" "${Channel04_resist}"
read_channel_and_convert "05" "18" ${High_Position} "${Channel05_name}" "${Channel05_resist}"
read_channel_and_convert "06" "1c" ${Low_Position} "${Channel06_name}" "${Channel06_resist}"
read_channel_and_convert "07" "1c" ${High_Position} "${Channel07_name}" "${Channel07_resist}"
read_channel_and_convert "08" "20" ${Low_Position} "${Channel08_name}" "${Channel08_resist}"
read_channel_and_convert "09" "20" ${High_Position} "${Channel09_name}" "${Channel09_resist}"
read_channel_and_convert "10" "24" ${Low_Position} "${Channel10_name}" "${Channel10_resist}"
read_channel_and_convert "11" "24" ${High_Position} "${Channel11_name}" "${Channel11_resist}"
read_channel_and_convert "12" "28" ${Low_Position} "${Channel12_name}" "${Channel12_resist}"
read_channel_and_convert "13" "28" ${High_Position} "${Channel13_name}" "${Channel13_resist}"
read_channel_and_convert "14" "2c" ${Low_Position} "${Channel14_name}" "${Channel14_resist}"
read_channel_and_convert "15" "2c" ${High_Position} "${Channel15_name}" "${Channel15_resist}"

@ -17,3 +17,8 @@
### 脚本模板 ### 脚本模板
- 简单的循环模板 [template_loop.sh](./03.template/template_loop.sh) - 简单的循环模板 [template_loop.sh](./03.template/template_loop.sh)
### BMC工具脚本
- Linux系统下一键收集日志 [Linux_CollectOnekeylog.sh](./07.bmc_tool_script/Linux_CollectOnekeylog.sh)
- Windows系统下一键收集日志 [Windows_CollectOnekeylog.bat](./07.bmc_tool_script/Windows_CollectOnekeylog.bat)
- BMC下快速读取ADC寄存器的数值 [read_adc_reg.sh](./07.bmc_tool_script/read_adc_reg.sh)