Browse - Programming Tips - Linux: detect if a machine is desktop, laptop, other

Date: 2019jun3
OS: Linux

Q.  Linux: detect if a machine is desktop, laptop, other

A.

hostnamectl status | grep Chassis
This will output something like
Chassis: desktop
The man page says the other possible vales are
Currently, the following chassis types are defined: "desktop", "laptop", "convertible", "server", "tablet", "handset", "watch", "embedded", as well as the special chassis types "vm" and "container" for virtualized systems that lack an immediate physical chassis.
If you want to use it in a script:
CH_LINE=$(hostnamectl status | grep Chassis) CH_ARRAY=($CH_LINE) CHASSIS=${CH_ARRAY[1]} echo chassis=$CHASSIS