Raspberry Pi/Serial Number
Jump to navigation
Jump to search
Serial Number
Simple Awk:
cat /proc/cpuinfo | grep Serial | awk '{print $3}'
Bash:
cat /proc/cpuinfo | perl -n -e '/^Serial[ ]*: ([0-9a-f]{16})$/ && print "$1\n"' grep -Po '^Serial\s*:\s*\K[[:xdigit:]]{16}' /proc/cpuinfo
Pure Bash:
pattern='^Serial.*([[:xdigit:]]{16})$' while read -r line do if [[ $line =~ $pattern ]] then echo "${BASH_REMATCH[1]}" fi done < /proc/cpuinfo
Bash Awk:
awk '/^Serial\s*:\s/{print $3}' /proc/cpuinfo
Python:
def getserial(): # Extract serial from cpuinfo file cpuserial = "0000000000000000" try: f = open('/proc/cpuinfo','r') for line in f: if line[0:6]=='Serial': cpuserial = line[10:26] f.close() except: cpuserial = "ERROR000000000" return cpuserial
References:
- setup - How do I get the serial number? - Raspberry Pi Stack Exchange - http://raspberrypi.stackexchange.com/questions/2086/how-do-i-get-the-serial-number