-2

I have a question. I would like to check when the raspi system starts or if the serial cpu is correct. If not, he would be rebooting. So he would be doing reboot loops all the time. I found the command to check the serial cpu command:

cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2

How to compare the result of this command to the value of eg 000000ddd0d0d?? And I do not know how to look like such a check script and where to put it in the Ubuntu system (/etc/init.d/rc.local ??).

Thank you for your help Sorry for my English. It is correctly??:

#!/bin/bash
STR=cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2
if $STR != '000000ddd0d0d'; then
reboot
  • Is this an attempt to lock down your software to a particular hardware? If so, see here and here why it's not gonna work. rc.local is especially easy to break since it can be easily bypassed at boot. – Dmitry Grigoryev Oct 19 '18 at 8:45
2

For a shell script comparison, you may wanna peruse this Other Comparison Operators. Also, you can probably achieve this with a case statement as shown below. I have tested the scripts on my Rpi0 and it works.

#!/bin/bash
STR=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2)
case $STR in
 000000ddd0d0d) reboot;;
 default) echo "Unknown CPU ID of $STR";;
esac

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.