-1

I am trying to create a python script that runs on Linux, but in my script I want to check on which linux distribution it's running.

I found this code:

import platform
print(platform.linux_distribution())

but this returns: ('Ubuntu', '18.04', 'bionic') And all I need to check is if it's Ubuntu / centOS... (doesn't matter which version) How can I grep the first value and do a 'if' on it?

  • have you tried `platform.linux_distribution()[0]` already? – blues Nov 29 '20 at 08:59
  • Does this answer your question? [How to get the system info with Python?](https://stackoverflow.com/questions/3103178/how-to-get-the-system-info-with-python) – Ulrich Eckhardt Nov 29 '20 at 09:58

1 Answers1

0

The return value is a tuple , you can use the index to fetch the desired value

from platform import linux_distribution

dist_tup = linux_distribution()

if dist_tup[0] == "Ubuntu":
   ##### Do Something
else:
   ##### Do something else
Vaebhav
  • 4,672
  • 1
  • 13
  • 33