Programmatically detect whether current Ubuntu version is lower or greater than Ubuntu 12.04

StackOverflow https://stackoverflow.com/questions/14559451

質問

I'm working on java web application where logic will be different based on the os version.

Currently we deploy our application both on Ubuntu 12.04 and Ubuntu 10. The Web App allows to change DNS nameservers through its UI. The application deployed in Ubuntu 10 keeps DNS name servers on etc/resolv.conf but Ubuntu 12.04 keeps them in etc/network/interfaces.

When storing DNS nameservers logic would be like

if(ubuntuVersion < ubuntu 12.04) then
    store it in etc/resolv.conf
else
    store it in etc/network/interfaces.

System.getProperty("os.name") or System.getProperty("os.arch") or any other system properties don't output Ubuntu package information.

How can the if part be implemented?

役に立ちましたか?

解決

Try the command lsb-release, It should return the release version of the distribution. You should be able to extract the version from the output.

Running just

lsb_release --release --short

will return the ubuntu version number

他のヒント

You can get the OS version with:

lsb_release -a|grep Release|cut -f2

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top