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?
[Solved] Get Linux version and name
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
[Solved] Get Linux version and name
Last edited by AndyGable on Thursday 5th October 2023 9:10pm, edited 1 time in total.
Re: Get Linux version and name
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.
Amare memorentes atque deflentes ad mortem silenter labimur.
- cogier
- Site Admin
- Posts: 1127
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Get Linux version and name
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: -
Output: -
Operating System: Linux Mint 21.2
Kernel: Linux 5.15.0-84-generic
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
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: Get Linux version and name
Hicogier 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
Just a update the above it works well but on my system I had to change it from System to Operating
Re: Get Linux version and name
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:53pmHicogier 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
Just a update the above it works well but on my system I had to change it from System to Operating
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Get Linux version and name
Really?AndyGable wrote: ↑Wednesday 20th September 2023 10:53pmHicogier 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
Just a update the above it works well but on my system I had to change it from System to Operating
hostnamectl | grep System does not work for you?
If at first you don't succeed , try doing something differently.
BruceS
BruceS
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: Get Linux version and name
No not on Debian 12BruceSteers wrote: ↑Thursday 21st September 2023 11:15pmReally?AndyGable wrote: ↑Wednesday 20th September 2023 10:53pmHicogier 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
Just a update the above it works well but on my system I had to change it from System to Operating
hostnamectl | grep System does not work for you?
Re: Get Linux version and name
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.
Amare memorentes atque deflentes ad mortem silenter labimur.
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Get Linux version and name
It's working fine on my debian 12AndyGable wrote: ↑Friday 22nd September 2023 8:13amNo not on Debian 12BruceSteers wrote: ↑Thursday 21st September 2023 11:15pmReally?
hostnamectl | grep System does not work for you?
How about this...
Code: Select all
lsb_release -ds 2>/dev/null; uname -sr
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
BruceS
- Technopeasant
- Posts: 144
- Joined: Saturday 13th July 2019 6:50pm
- Location: Stony Plain, Alberta, Canada
- Contact:
Re: [Solved] Get Linux version and name
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.
https://gambaswiki.org/wiki/comp/gb/system
Seems it can tell you it is Linux, but not what exact distro and version of Linux.