I plan to enhance the htf-common-issues.php script (from http://gitplace.net/pixcept/ispconfig-tools/blob/master/htf-common-issues.php) so it writes also the operating system name and version. I have a short test script to verify how the OS version can be determined on different systems. It works well on Ubuntu and Debian systems since they have lsb_release installed by default (at least on all systems I have checked). But for other systems I would like help. So run the attached PHP script and post result here. The script is hopefully simple to check it does not send me your password file or do other nasty stufs. PHP: #!/usr/bin/php -q<?php/* Test which operation system script is running on Taleman 2019*/ini_set('display_errors', 'On');$lsbrel='/usr/bin/lsb_release';$rhatrel = '/etc/redhat-release';$os_version = '';/* echo "Next is if\n"; */if (file_exists($lsbrel)) { echo "Found lsbrel\n"; $os_version = shell_exec($lsbrel.' -d');} elseif (file_exists($rhatrel)) { /* echo "redhatrel does exist\n"; */ $os_version = shell_exec('cat '.$redhatrel);} else { $lslisting = shell_exec('ls -lhd /etc/*versio* /etc/*releas* /etc/*issue*');}if ($os_version == '') { echo "ls listing:\n".$lslisting;} else { echo "OS version is ".$os_version;}
I just tried something similar in a project. I found out that the file "/etc/os-version" should be the new standard (at least it is used by systemd systems [1]). It should work on recent Debian, OpenSUSE, Fedora, ArchLinux.. Someone already shared a code snipped to read that file into an array[2] Hope this helps [edit] Sorry, wanted to share the links but the system doesn't like me yet. Links are: Code: [1] www.freedesktop.org/software/systemd/man/os-release.html [2] https://stackoverflow.com/a/42397673
Thanks, this does help. But [1] you referred says the name of the file is /etc/os-release, not os-version. On Debian 9.9 at least that file does not show the subversion, it only says it is Debian 9. I made version 2 that examines /etc/os-release if info has not been found before that. On my Debian 9.9 this writes: Code: $ ./os-version-check.php Found lsbrel This scipt is version 2 OS version is Description: Debian GNU/Linux 9.9 (stretch) Here is the new code: PHP: #!/usr/bin/php -q<?php/* Test which operation system script is running on Taleman 2019*/ini_set('display_errors', 'On');$progversion="2";$lsbrel='/usr/bin/lsb_release';$rhatrel = '/etc/redhat-release';$osrelease='/etc/os-release';$os_version = '';/* echo "Next is if\n"; */if (file_exists($lsbrel)) { echo "Found lsbrel\n"; $os_version = shell_exec($lsbrel.' -d');} elseif (file_exists($rhatrel)) { /* echo "redhatrel does exist\n"; */ $os_version = shell_exec('cat '.$redhatrel);} elseif (file_exists($osrelease)) { $os_version = shell_exec('cat '.$osrelease.' | grep "PRETTY_NAME"');} else { $lslisting = shell_exec('ls -lhd /etc/*versio* /etc/*releas* /etc/*issue*');}echo "This scipt is version ".$progversion."\n";if ($os_version == '') { echo "ls listing:\n".$lslisting;} else { echo "OS version is ".$os_version;}?>
I found the code in ISPConfig source, but that is very complicated and long. There was, however, /etc/*release files for a few additional operating systems, so useful find. Meanwhile, this is from Debian Buster without lsb_release installed: Code: root@posti:/tmp# ./foo.php This scipt is version 2 OS version is PRETTY_NAME="Debian GNU/Linux 10 (buster)" root@posti:/tmp# type -a lsb_release -bash: type: lsb_release: not found
May be a one line code Code: lsb_release -ds 2>/dev/null || awk -F= '$1=="PRETTY_NAME" { print $2 ;}' /etc/*elease | tr -d '"' Or like this: Code: <?php /* Test which operation system script is running on (c) Taleman 2019 */ ini_set('display_errors', 'On'); $progversion="2"; $os_version = shell_exec('lsb_release -ds 2>/dev/null || awk -F= \'$1==\"PRETTY_NAME\" { print $2 ;}\' /etc/*elease | tr -d \'\"\''); $lslisting = shell_exec('ls -lhd /etc/*versio* /etc/*releas* /etc/*issue*'); echo "This scipt is version: ".$progversion."\n"; if (!empty($os_version)) echo "OS version is: ".$os_version; else echo "ls listing:\n".$lslisting; ?> Tested only in debian / ubuntu. I don't know if this will work on other linux. Edited: I dropped cat /etc/redhat-release from the suggestion as redhat or itsderivative also seems to use os_release.
Here is version 3 of the script. I added Gentoo and SuSE detection after looking at the code in ISPConfig. os-release is used as last resort, since it does not show the subversion of the OS. Code: PHP: #!/usr/bin/php -q<?php/* Test which operation system script is running on Taleman 2019*/ini_set('display_errors', 'On');$progversion="3";$lsbrel='/usr/bin/lsb_release';$rhatrel = '/etc/redhat-release';$osrelease='/etc/os-release';$suserel = '/etc/SuSE-release';$gentoorel = '/etc/gentoo-release';$os_version = '';/* echo "Next is if\n"; */if (file_exists($lsbrel)) { echo "Found lsbrel\n"; $os_version = shell_exec($lsbrel.' -d');} elseif (file_exists($rhatrel)) { /* echo "redhatrel does exist\n"; */ $os_version = shell_exec('cat '.$redhatrel);} elseif (file_exists($suserel)) { $os_version = shell_exec('cat '.$suserel);} elseif (file_exists($gentoorel)) { $os_version = shell_exec('cat '.$gentoorel);} elseif (file_exists($osrelease)) { $os_version = shell_exec('cat '.$osrelease.' | grep "PRETTY_NAME"');} else { $lslisting = shell_exec('ls -lhd /etc/*versio* /etc/*releas* /etc/*issue*');}echo "This scipt is version ".$progversion."\n";if ($os_version == '') { echo "ls listing:\n".$lslisting;} else { echo "OS version is ".$os_version;}?>
I did mention that in my suggestion. @Taleman I already tested your code in Ubuntu 18.04 and it is working fine. But I also consider your code is a bit long since usingl sb_release -ds or checking os_release is quite a standard and sufficient while checking others has become quite obsolete and unnecessary.
I started writing this addition to htf-common-issues after several times willing to help ISPConfig users but not knowing what OS they have seeing that helping is unnecessarily difficult. So I wanted someting that always shows what OS is involved, so I copied the alternatives from ISPConfig source. I agree that Debian and Ubuntu together are the majority of ISPConfig installations, and adding CentOS the proportion is close to 100%. But I find it is not that many lines of code and it should show something useful in all cases. I am not a PHP coder, I stopped with PHP when PHP 5 came out and all my PHP 4 code needed rewriting. So the code most likely could be better, but at least now it is not very complicated.