[Solved] Get Linux version and name

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Solved] Get Linux version and name

Post by AndyGable »

Hi Everyone ;)

Just out of curiosity is there a way in Gambas to get it to display on a label what Linux it is running on and what version the kernel is?

For example I have Debian 12 on my PC's and on my about screen I would like to show something like

"this app is running on Debian 12 (kernal 6.1.0-9-amd64) please let our support people know if you have to call us"

Can this be done with Gambas?
Last edited by AndyGable on Thursday 5th October 2023 9:10pm, edited 1 time in total.
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Get Linux version and name

Post by vuott »

I have Linux Mint... however I would suggest :? this solution:
Public Sub Main()

  Dim s As String

  s = "Operating System: " & File.Load("/etc/issue.net")
  s &= "Architectue:      " & System.Architecture
  s &= "\nKernel:           " & Scan(File.Load("/proc/version"), "*(*")[0]

  Print s

End
Last edited by vuott on Thursday 21st September 2023 9:30pm, edited 4 times in total.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Get Linux version and name

Post by cogier »

I thought that this was an interesting question. As a result, I discovered that all distros that use Systemd, and that is most distros now, have a useful command called hostnamectl. This produces quite a bit of interesting information. The following code will return the information you are looking for: -

 Dim s1, s2 As String
  
  Shell "hostnamectl | grep System" To s1
  Shell "hostnamectl | grep Kernel" To s2
  Print s1; s2


Output: -
Operating System: Linux Mint 21.2
Kernel: Linux 5.15.0-84-generic
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Get Linux version and name

Post by AndyGable »

cogier wrote: Wednesday 20th September 2023 1:02pm I thought that this was an interesting question. As a result, I discovered that all distros that use Systemd, and that is most distros now, have a useful command called hostnamectl. This produces quite a bit of interesting information. The following code will return the information you are looking for: -

 Dim s1, s2 As String
  
  Shell "hostnamectl | grep System" To s1
  Shell "hostnamectl | grep Kernel" To s2
  Print s1; s2


Output: -
Operating System: Linux Mint 21.2
Kernel: Linux 5.15.0-84-generic
Hi

Just a update the above it works well but on my system I had to change it from System to Operating
User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Get Linux version and name

Post by sadams54 »

Thanks for the info. I was not aware of hostnamectl, you gave me something new to play with.




AndyGable wrote: Wednesday 20th September 2023 10:53pm
cogier wrote: Wednesday 20th September 2023 1:02pm I thought that this was an interesting question. As a result, I discovered that all distros that use Systemd, and that is most distros now, have a useful command called hostnamectl. This produces quite a bit of interesting information. The following code will return the information you are looking for: -

 Dim s1, s2 As String
  
  Shell "hostnamectl | grep System" To s1
  Shell "hostnamectl | grep Kernel" To s2
  Print s1; s2


Output: -
Operating System: Linux Mint 21.2
Kernel: Linux 5.15.0-84-generic
Hi

Just a update the above it works well but on my system I had to change it from System to Operating
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Get Linux version and name

Post by BruceSteers »

AndyGable wrote: Wednesday 20th September 2023 10:53pm
cogier wrote: Wednesday 20th September 2023 1:02pm I thought that this was an interesting question. As a result, I discovered that all distros that use Systemd, and that is most distros now, have a useful command called hostnamectl. This produces quite a bit of interesting information. The following code will return the information you are looking for: -

 Dim s1, s2 As String
  
  Shell "hostnamectl | grep System" To s1
  Shell "hostnamectl | grep Kernel" To s2
  Print s1; s2


Output: -
Operating System: Linux Mint 21.2
Kernel: Linux 5.15.0-84-generic
Hi

Just a update the above it works well but on my system I had to change it from System to Operating
Really?
hostnamectl | grep System does not work for you?
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Get Linux version and name

Post by AndyGable »

BruceSteers wrote: Thursday 21st September 2023 11:15pm
AndyGable wrote: Wednesday 20th September 2023 10:53pm
cogier wrote: Wednesday 20th September 2023 1:02pm I thought that this was an interesting question. As a result, I discovered that all distros that use Systemd, and that is most distros now, have a useful command called hostnamectl. This produces quite a bit of interesting information. The following code will return the information you are looking for: -

 Dim s1, s2 As String
  
  Shell "hostnamectl | grep System" To s1
  Shell "hostnamectl | grep Kernel" To s2
  Print s1; s2


Output: -
Operating System: Linux Mint 21.2
Kernel: Linux 5.15.0-84-generic
Hi

Just a update the above it works well but on my system I had to change it from System to Operating
Really?
hostnamectl | grep System does not work for you?
No not on Debian 12
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Get Linux version and name

Post by vuott »

AndyGable wrote: Tuesday 19th September 2023 10:46pm I have Debian 12 on my PC
I modified the code in my suggestion above.
Can you test it with your Debian 12 ?
Thank you.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Get Linux version and name

Post by BruceSteers »

AndyGable wrote: Friday 22nd September 2023 8:13am
BruceSteers wrote: Thursday 21st September 2023 11:15pm
AndyGable wrote: Wednesday 20th September 2023 10:53pm

Hi

Just a update the above it works well but on my system I had to change it from System to Operating
Really?
hostnamectl | grep System does not work for you?
No not on Debian 12
It's working fine on my debian 12

How about this...

Code: Select all

lsb_release -ds 2>/dev/null; uname -sr
Debian GNU/Linux 12 (bookworm)
Linux 6.1.0-12-amd64


Or with gambas...
Dim sSystem, sKernel As String
   
 Shell "lsb_release -ds 2>/dev/null" To sSystem
 Shell "uname -sr" To sKernel
 
Print sSystem, sKernel
If at first you don't succeed , try doing something differently.
BruceS
User avatar
Technopeasant
Posts: 144
Joined: Saturday 13th July 2019 6:50pm
Location: Stony Plain, Alberta, Canada
Contact:

Re: [Solved] Get Linux version and name

Post by Technopeasant »

A bit of a shame that this is not implemented here.

https://gambaswiki.org/wiki/comp/gb/system

Seems it can tell you it is Linux, but not what exact distro and version of Linux.
Technical director,
Piga Software
http://icculus.org/piga/
Post Reply