程式扎記: [Linux 常見問題] How to know if the running platform is Ubuntu or CentOS?

標籤

2015年9月17日 星期四

[Linux 常見問題] How to know if the running platform is Ubuntu or CentOS?

Source From Here 
Question 
I know the commands to check the name of the Linux machine running on my machine. For example: 
- Ubuntu 
# uname -a
Linux ubuntu 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

- CentOS 
# rpm -qa \*-release\* | grep centos
centos-release-7-1.1503.el7.centos.2.8.x86_64

How do I get the output from the terminal and compare to see if it is UBUNTU or CENTOS and perform the following commands? 
# apt-get install updates

Or 
# yum update

How-To 
My recommendation is to use this command instead: 
# python -mplatform | grep Ubuntu && sudo apt-get update || sudo yum update

python platform module will work on both systems, the rest of the command will check if Ubuntu is returned by python and run apt-get else yum.

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!