
Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Thanks guys. I know 'uname -r' would return the kernel version, but I'm
looking for the actual OS version.
I'm writing a code to check if the machine has the matching version
from my meta-data file. The only way to obtain the OS version from a
Linux machine is through /etc/issue file.
Regular expression is one way to implement this, isn't it?
> > Anyway, these are the strings that I would expect (depends on which
> > Linux machine I run on):
[quoted text clipped - 25 lines]
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
HansF - 15 Jun 2005 17:04 GMT
On Wed, 15 Jun 2005 08:38:20 -0700, kenshin interested us by writing:
> I'm writing a code to check if the machine has the matching version
> from my meta-data file. The only way to obtain the OS version from a
> Linux machine is through /etc/issue file.
As long as you realize that /etc/issue is only initialized by the vendor,
and many SAs customize the contents. (For example, one recommendation is
http://web.tampabay.rr.com/batcave/ServerBuilds.htm#Issue ...)
If you want the distro's release info, check the files /etc/*-release (eg:
/etc/redhat-release
/etc/debian_version
/etc/SuSE-release
/etc/slackware-version
/etc/gentoo-release
/etc/cobalt-release
Again, not entirely consistent, but possibly closer to what you want.
(Still not sure what you define as 'OS', though.)

Signature
Hans Forbrich
Andrew Thompson - 15 Jun 2005 17:26 GMT
> ..The only way to obtain the OS version ..
As in <http://www.physci.org/pc/property.jsp?prop=os.version>
>..from a Linux machine is through /etc/issue file.
?

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Gordon Beaton - 15 Jun 2005 17:40 GMT
> Thanks guys. I know 'uname -r' would return the kernel version, but I'm
> looking for the actual OS version.
>
> I'm writing a code to check if the machine has the matching version
> from my meta-data file.
Then why don't you just check if the whole string matches?
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
kenshin@prontomail.com - 15 Jun 2005 19:30 GMT
Thank you all for the valuable feedbacks and suggestions! :)
After experimenting a bit with regular expressions, this seems to do
the trick:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class OSTest
{
public static void main (String[] args)
{
String sIssue = "Red Hat 88 (Update 3456)";
String sRegex = "\\d+[.]\\d+|\\d+";
System.out.println (parseIssueFileForVersionNumber( sIssue, sRegex
));
}
private static String parseIssueFileForVersionNumber ( String sIn,
String sPattern)
{
Pattern patternLanguage = Pattern.compile( sPattern );
Matcher matcher = patternLanguage.matcher( sIn );
matcher.find();
int nStart = matcher.start();
int nStop = matcher.end();
sIn = sIn.substring( nStart, nStop);
return sIn;
}
}