The easiest way to get hardware serial and related information is using “dmidecode“.
The command below should give you exactly what you need :
dmidecode -s system-serial-number
The command above does not usually work with “clone” computers/servers. Alternatively, you may use the command below, which will output all parts serial number availables :
dmidecode | grep "Serial Number:"