[SOLVED] How to detect hardware e.g. CPU name, Video Adapter name, Harddisk name lazarus / 32-Linux ---------------------------------------------------------------------- Hartmut · 2020-05-01 17:39 I have written some small console programs which shall run on 2 different computers and which shall behave a little different on them. Therefore I want to detect, on which hardware a program is running. Software and operating systems on both computers are identical. To set a different environment variable had to be repeated manually after each copy of PC #1 to PC #2 = uncomfortable. To use a different command line parameter is uncomfortable too (and often I would forget it) => to detect the hardware would be the best way. The differences between the 2 computers are e.g.:  - name of CPU  - name of Video Adapter  - name of Harddisk  - name of Mainboard  - BIOS date How can I read information like this on Ubuntu 18.04? One of them would be enough (I would prefer an easy solution). I use FPC 3.0.4. Thanks in advance. ---------------------------------------------------------------------- TRon · 2020-05-01 17:52 cat /proc/cpuinfo ? I take it you are able to figure out yourself how you can read that without resorting to bash (look for it on the forums) ? ---------------------------------------------------------------------- MarkMLl · 2020-05-01 19:29 > - name of CPU lscpu output. Most of that is from the /proc tree but it does add value. > - name of Video Adapter lspci output and parsing /var/log/Xorg.0.log, with the caveat that the content of the latter might change (a lot) with distro version. > - name of Harddisk Most of this will only be visible to root, but lsblk might help. Might be some useful stuff in /sys/class/block > - name of Mainboard Possibly via snmp, otherwise look again at lspci output. > - BIOS date Likely to be in dmesg output, but that will be accessible to root only. HTH. MarkMLl ---------------------------------------------------------------------- winni · 2020-05-01 19:42 Hi! name of CPU: /proc/cpuinfo contains the number of CPUs, the vendor and the model name name of Harddisk: /proc/scsi/scsi contains the vendor and model name of all attached drives: HD, CD/DVD, SDD The files in the /proc directory ar readable for everybody. Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-01 20:22 Quote from: winni on May 01, 2020, 09:42:34 pmname of Harddisk: /proc/scsi/scsi contains the vendor and model name of all attached drives: HD, CD/DVD, SDD You can no longer rely on that being present. MarkMLl ---------------------------------------------------------------------- winni · 2020-05-01 21:08 Quote from: MarkMLl on May 01, 2020, 10:22:37 pm You can no longer rely on that being present. MarkMLl Hi! Where is that information written? That is new to me. Winni ---------------------------------------------------------------------- avra · 2020-05-01 23:10 Quote from: Hartmut on May 01, 2020, 07:39:03 pmI want to detect, on which hardware a program is running.If your goal is software protection, then you might want to take a look at https://wiki.freepascal.org/OnGuard ---------------------------------------------------------------------- MarkMLl · 2020-05-02 07:45 Quote from: winni on May 01, 2020, 11:08:32 pmQuote from: MarkMLl on May 01, 2020, 10:22:37 pm You can no longer rely on that being present. MarkMLl Hi! Where is that information written? That is new to me. Winni GOK, but that particular tree started being deprecated at about the time that IDE discs were moved onto the SCSI subsystem with e.g. a change in the way the buses could be forcibly rescanned to detect hotplugged devices. The system in front of me- SATA+md on kernel 4.19- doesn't have it, neither do a couple of servers I've just checked, neither does an older system on Debian "Jessie" with 3.16. I don't think I've got anything to hand with "real" SCSI to check, but even there the functionality's been changing since (finger-in-air guess) somewhere around 2.6. Obviously during that progression things have been added like the /dev/disk tree, but I'm not really sure whether that helps OP since he was specifically asking for identifying/diagnostic info rather than just UUIDs or stuff that was likely to change if a program was moved around. MarkMLl ---------------------------------------------------------------------- Hartmut · 2020-05-02 08:06 Thank you very much for all of this information. I'm a beginner on Linux to this hardware stuff and with your infos I did a lot of interesting experiments and learned a lot. My solution is to read file '/proc/cpuinfo' directly to get the name of the CPU. That was the easiest way for me. ---------------------------------------------------------------------- lucamar · 2020-05-02 08:17 Most of the information you want can be parsed out from the output of lshw -short. For example on this machine it gives me: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [... among other things ...] /0/4                            processor      Mobile Intel(R) Pentium(R) 4 CPU 3.06GHz/0/100/1/5                    display        RS250 [Mobility Radeon 7000 IGP]/0/100/14.1/0      /dev/sda     disk           160GB WDC WD1600BEVE-0/0/100/14.1/1      /dev/cdrom3  disk           DVD-RAM UJ-820S [... and lots more like it ...] There are other (installable) "lsXXX" commands that can give you other and/or extended information; to see which you have type in a terminal: Code: [Select]apropos ^lsThat should give you a list of all commands starting with "ls" for which a man page exists. ---------------------------------------------------------------------- MarkMLl · 2020-05-02 08:27 Quote from: lucamar on May 02, 2020, 10:17:11 amMost of the information you want can be parsed out from the output of lshw -short. For example on this machine it gives me: Not on Debian by default. Can't speak for Ubuntu. OP: note that the CPU/core numbers in /proc/cpuinfo are architecture- specific, and might not be contiguous. MarkMLl ---------------------------------------------------------------------- TRon · 2020-05-02 08:51 Quote from: Hartmut on May 01, 2020, 07:39:03 pmHow can I read information like this on Ubuntu 18.04? One of them would be enough (I would prefer an easy solution). I use FPC 3.0.4. Thanks in advance. So any one  ;-p proposed will do. Just run a checksum over one of the proposals and it would be enough for TS to distinguish between two machines. Reading a user of app directory contents would probably be enough. Or free diskspace or a random pixel on the desktop for that matter :-) ---------------------------------------------------------------------- lucamar · 2020-05-02 08:54 Quote from: MarkMLl on May 02, 2020, 10:27:07 amNot on Debian by default. Can't speak for Ubuntu. Oops! You're right; after a closer look it seems it's one of the utils I install on auto-pilot after setting up a new system, so it's on all my systems ---------------------------------------------------------------------- winni · 2020-05-02 14:06 Quote from: MarkMLl on May 02, 2020, 09:45:31 amQuote from: winni on May 01, 2020, 11:08:32 pmQuote from: MarkMLl on May 01, 2020, 10:22:37 pm You can no longer rely on that being present. MarkMLl Hi! Where is that information written? That is new to me. Winni GOK, but that particular tree started being deprecated at about the time that IDE discs were moved onto the SCSI subsystem with e.g. a change in the way the buses could be forcibly rescanned to detect hotplugged devices. The system in front of me- SATA+md on kernel 4.19- doesn't have it, neither do a couple of servers I've just checked, neither does an older system on Debian "Jessie" with 3.16. I don't think I've got anything to hand with "real" SCSI to check, but even there the functionality's been changing since (finger-in-air guess) somewhere around 2.6. Obviously during that progression things have been added like the /dev/disk tree, but I'm not really sure whether that helps OP since he was specifically asking for identifying/diagnostic info rather than just UUIDs or stuff that was likely to change if a program was moved around. MarkMLl Hi! I use the Kernel 5.6.6-1 since some days and the information in /proc is as above shown. Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-02 16:51 Quote from: winni on May 02, 2020, 04:06:36 pmI use the Kernel 5.6.6-1 since some days and the information in /proc is as above shown. Winni It will be distro-specific, and depend on how the kernel is configured and/or what modules are loaded. See e.g. https://serverfault.com/questions/236711/where-is-proc-scsi-scsi-in- debian-6 MarkMLl ---------------------------------------------------------------------- winni · 2020-05-02 17:23 Thanx for the info. Again it is Debian which makes trouble .... Winni ---------------------------------------------------------------------- winni · 2020-05-02 17:57 Hi! Whatever is wrong: The proc manpage for Debian Buster says that the pseudo file /proc/scsi/scsi exist. https://manpages.debian.org/buster/manpages-de/proc.5.de.html Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-02 19:57 Quote from: winni on May 02, 2020, 07:57:44 pmHi! Whatever is wrong: The proc manpage for Debian Buster says that the pseudo file /proc/scsi/scsi exist. https://manpages.debian.org/buster/manpages-de/proc.5.de.html Winni It's wrong. And German >:-) MarkMLl ---------------------------------------------------------------------- Hartmut · 2020-05-03 07:29 Quote from: lucamar on May 02, 2020, 10:17:11 amMost of the information you want can be parsed out from the output of lshw -short. For example on this machine it gives me: ... There are other (installable) "lsXXX" commands that can give you other and/or extended information; to see which you have type in a terminal: Code: [Select]apropos ^lsThat should give you a list of all commands starting with "ls" for which a man page exists. Thank you lucamar for that additional interesting informations. Because I have Ubuntu and not Debian I can use "lshw -short". I added lshw and apropos to my personal list of helpfull commands. Quote from: MarkMLl on May 02, 2020, 10:27:07 am... OP: note that the CPU/core numbers in /proc/cpuinfo are architecture- specific, and might not be contiguous. Thanks for that info too.