I'm trying to get python script to verify if the Linux server is the os release, 5,6 or 7
Can someone help me to guide me to the right direction.

import os
import platform
import sys

os_release = (str(platform.linux_distribution()[0]))

if os_release == "5":
os.system("df -h")
elif os_release == "6":
os.system("date")
elif os_release == "7":
os.system("calc")

Thank you,
pirulo64

Recommended Answers

All 2 Replies

According to the python documentation, platform.linux_distribution() returns a tuple (distname, version, id). For example on my computer

$ python -c "import platform; print(platform.linux_distribution())"
('Ubuntu', '14.04', 'trusty')

What does it print on your server ?

commented: Yh, this should be the way 2 go +6

Thanks it just what I need it.

python -c "import platform; print(platform.linux_distribution())[2]"
Santiago
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.