実行中の Linux ディストリビューションのバージョンも含めた判別です。
次のいずれかなら判別できます。
Ubuntu 14 Ubuntu 16 CentOS 6 CentOS 7 Red Hat Enterprise Linux 7 Red Hat Enterprise Linux 6
ファイル /etc/issue と /etc/*release の内容から判別できます。
cat /etc/issue /etc/*release を実行し、その出力結果に次の文字列があれば、該当する各ディストリビューション/バージョンが動作しています。
Ubuntu 14 Ubuntu 16 CentOS release 6 CentOS Linux release 7 Red Hat Enterprise Linux Server release 7 Red Hat Enterprise Linux Server release 6
例えば、下記の例では、「CentOS release 6」が動作しています。
$ cat /etc/issue /etc/*release CentOS release 6.8 (Final) Kernel \r on an \m CentOS release 6.8 (Final) CentOS release 6.8 (Final) CentOS release 6.8 (Final)
以下、各ディストリビューション/バージョン毎に、参照するファイルです。
CentOS7 は /etc/centos-release、RedHat7 では /etc/redhat-release、それ以外は /etc/issue からわかります。
Debian では /etc/issue からわかります。
$ cat /etc/issue Debian GNU/Linux 6.0 \n \l
Ubuntu では /etc/issue からわかります。
$ cat /etc/issue Ubuntu 14.04.5 LTS \n \l
CentOS6 では /etc/issue の1行目からわかります。
$ cat /etc/issue CentOS release 6.8 (Final) Kernel \r on an \m
RedHat6 では /etc/issue の1行目からわかります。
$ cat /etc/issue Red Hat Enterprise Linux Server release 6.5 (Santiago) Kernel \r on an \m
CentOS7、RedHat7 は /etc/issue からはわかりません。
$ cat /etc/issue \S Kernel \r on an \m
CentOS7 では /etc/centos-release からわかります。
$ cat /etc/centos-release CentOS Linux release 7.3.1611 (Core)
RedHat7 では /etc/redhat-release からわかります。
$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.1 (Maipo)
コメント