[Solved] Get Linux version and name

Post

Posted
Rating:
#1 (In Topic #1095)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
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?
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
I have Linux Mint… however I would suggest :? this solution:

Code (gambas)

  1. Public Sub Main()
  2.  
  3.  
  4.   s = "Operating System: " & File.Load("/etc/issue.net")
  5.   s &= "Architectue:      " & System.Architecture
  6.   s &= "\nKernel:           " & Scan(File.Load("/proc/version"), "*(*")[0]
  7.  
  8.   Print s
  9.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
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: -

Code (gambas)

  1.  Dim s1, s2 As String
  2.  
  3.   Shell "hostnamectl | grep System" To s1
  4.   Shell "hostnamectl | grep Kernel" To s2
  5.   Print s1; s2

Output: -
Operating System: Linux Mint 21.2
                  Kernel: Linux 5.15.0-84-generic
Online now: Yes Back to the top

Post

Posted
Rating:
#4
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

cogier said

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: -

Code (gambas)

  1.  Dim s1, s2 As String
  2.  
  3.   Shell "hostnamectl | grep System" To s1
  4.   Shell "hostnamectl | grep Kernel" To s2
  5.   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
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
Thanks for the info. I was not aware of hostnamectl, you gave me something new to play with.





AndyGable said

cogier said

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: -

Code (gambas)

  1.  Dim s1, s2 As String
  2.  
  3.   Shell "hostnamectl | grep System" To s1
  4.   Shell "hostnamectl | grep Kernel" To s2
  5.   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
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

cogier said

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: -

Code (gambas)

  1.  Dim s1, s2 As String
  2.  
  3.   Shell "hostnamectl | grep System" To s1
  4.   Shell "hostnamectl | grep Kernel" To s2
  5.   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?
Online now: No Back to the top

Post

Posted
Rating:
#7
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

AndyGable said

cogier said

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: -

Code (gambas)

  1.  Dim s1, s2 As String
  2.  
  3.   Shell "hostnamectl | grep System" To s1
  4.   Shell "hostnamectl | grep Kernel" To s2
  5.   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
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
vuott is in the usergroup ‘Regular’

AndyGable said

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 !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

BruceSteers said

AndyGable said



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

lsb_release -ds 2>/dev/null; uname -sr

Debian GNU/Linux 12 (bookworm)
Linux 6.1.0-12-amd64


Or with gambas…

Code (gambas)

  1. Dim sSystem, sKernel As String
  2.    
  3.  Shell "lsb_release -ds 2>/dev/null" To sSystem
  4.  Shell "uname -sr" To sKernel
  5.  
  6. Print sSystem, sKernel
  7.  
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
A bit of a shame that this is not implemented here.

/comp/gb/system - Gambas Documentation

Seems it can tell you it is Linux, but not what exact distro and version of Linux.
Online now: No Back to the top
1 guest and 0 members have just viewed this.