Skip to main content
Typo fix
Source Link
Toby Speight
  • 88.3k
  • 14
  • 104
  • 327

Below is a section from the dmidocedmidecode output. There is a part of this section that I want to break down. I want to get the 4bytes4 bytes after pattern 01 85 3001 85 30. And I want to change the byte order. Then I will compare with the hex strings I have.

....... 
Handle 0x0027, DMI type 219, 106 bytes
OEM-specific Type
        Header and Data:
                DB 6A 27 00 01 04 01 45 02 00 90 06 *01 85 30* 20
                00 00 00 00 40 00 00 03 1F 24 02 C9 02 60 44 02
                FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF 03 00 00 00 80 00 00 00
                00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                00 04 FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF FF FF
.......

I prepared a bash script and it works, is there a better way?

#!/bin/bash

id_array=("00000020", "00000040")
unique_id=$(dmidecode -t 219 | grep "01 85 30" -A 1 | xargs | cut -c 46-56 | tr -d '[:space:]' | grep -o .. | tac | paste -sd ''  -)
if [[ " ${id_array[*]} " == *"$unique_id"* ]];
then
  echo "1"
else
  echo "0"
fi

Below is a section from the dmidoce output. There is a part of this section that I want to break down. I want to get the 4bytes after pattern 01 85 30. And I want to change the byte order. Then I will compare with the hex strings I have.

....... 
Handle 0x0027, DMI type 219, 106 bytes
OEM-specific Type
        Header and Data:
                DB 6A 27 00 01 04 01 45 02 00 90 06 *01 85 30* 20
                00 00 00 00 40 00 00 03 1F 24 02 C9 02 60 44 02
                FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF 03 00 00 00 80 00 00 00
                00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                00 04 FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF FF FF
.......

I prepared a bash script and it works, is there a better way?

#!/bin/bash

id_array=("00000020", "00000040")
unique_id=$(dmidecode -t 219 | grep "01 85 30" -A 1 | xargs | cut -c 46-56 | tr -d '[:space:]' | grep -o .. | tac | paste -sd ''  -)
if [[ " ${id_array[*]} " == *"$unique_id"* ]];
then
  echo "1"
else
  echo "0"
fi

Below is a section from the dmidecode output. There is a part of this section that I want to break down. I want to get the 4 bytes after pattern 01 85 30. And I want to change the byte order. Then I will compare with the hex strings I have.

....... 
Handle 0x0027, DMI type 219, 106 bytes
OEM-specific Type
        Header and Data:
                DB 6A 27 00 01 04 01 45 02 00 90 06 *01 85 30* 20
                00 00 00 00 40 00 00 03 1F 24 02 C9 02 60 44 02
                FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF 03 00 00 00 80 00 00 00
                00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                00 04 FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF FF FF
.......

I prepared a bash script and it works, is there a better way?

#!/bin/bash

id_array=("00000020", "00000040")
unique_id=$(dmidecode -t 219 | grep "01 85 30" -A 1 | xargs | cut -c 46-56 | tr -d '[:space:]' | grep -o .. | tac | paste -sd ''  -)
if [[ " ${id_array[*]} " == *"$unique_id"* ]];
then
  echo "1"
else
  echo "0"
fi
Source Link

Getting Specific Value from Dmidecode Output with Bash Script

Below is a section from the dmidoce output. There is a part of this section that I want to break down. I want to get the 4bytes after pattern 01 85 30. And I want to change the byte order. Then I will compare with the hex strings I have.

....... 
Handle 0x0027, DMI type 219, 106 bytes
OEM-specific Type
        Header and Data:
                DB 6A 27 00 01 04 01 45 02 00 90 06 *01 85 30* 20
                00 00 00 00 40 00 00 03 1F 24 02 C9 02 60 44 02
                FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF 03 00 00 00 80 00 00 00
                00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                00 04 FF FF FF FF FF FF FF FF FF FF FF FF FF FF
                FF FF FF FF FF FF FF FF FF FF
.......

I prepared a bash script and it works, is there a better way?

#!/bin/bash

id_array=("00000020", "00000040")
unique_id=$(dmidecode -t 219 | grep "01 85 30" -A 1 | xargs | cut -c 46-56 | tr -d '[:space:]' | grep -o .. | tac | paste -sd ''  -)
if [[ " ${id_array[*]} " == *"$unique_id"* ]];
then
  echo "1"
else
  echo "0"
fi