LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-04-2007, 01:20 AM   #1
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,443

Rep: Reputation: 73
Script to determine if OS is Slackware and what version


Does anyone know a good solid way to automatically test if a Linux OS is Slackware and possibly (bonus) even determine the version?

I thought there was a command to do this but I cannot remember it. The only thing I can think of right now is to check the MACHTYPE env variable. This tells me I am running Slackware but not which version.

thanks in advance for any help.
 
Old 12-04-2007, 01:53 AM   #2
tommcd
Senior Member
 
Registered: Jun 2006
Location: Philadelphia PA USA
Distribution: Lubuntu, Slackware
Posts: 2,230

Rep: Reputation: 293Reputation: 293Reputation: 293
You could try "uname -a". I'm not on a linux box atm, but I think "uname -a" gives that info.

Last edited by tommcd; 12-04-2007 at 01:54 AM.
 
Old 12-04-2007, 02:12 AM   #3
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
Try
Code:
cat /etc/slackware-version
Other distros have similar files.

Eric
 
Old 12-04-2007, 02:33 AM   #4
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Rep: Reputation: 46
bash-3.1$ cat /var/log/Xorg.0.log | grep Operating
Build Operating System: Slackware 12.0 Slackware Linux Project
 
Old 12-04-2007, 02:37 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by Alien Bob View Post
Try
Code:
cat /etc/slackware-version
Other distros have similar files.

Eric
Yes, that's the best way, but there was a case recently here where it was missing (probably a system admin deleted the file). Then it would be much harder to tell. The other ways involve the kernel as stated before, but if it is custom, that won't help either. I'd say check for pkgtools (pkgtools-12.0.0-noarch-4 for 12.0), but those too can be uninstalled ... a bad idea, IMO. Then, you can check the xorg version and match it up:

Code:
X -version

X Window System Version 1.3.0
Release Date: 19 April 2007
X Protocol Version 11, Revision 0, Release 1.3
Build Operating System: Slackware 12.0 Slackware Linux Project
but then they could have built their own version. Check for glibc version ... but what if they don't have it installed ? ... and so on.

Conclusion: I think the best thing to do is test for all of these things in order with fallback tests in case previous ones fail. I mean test for /etc/slackware-version, then for kernel (uname -a), then for 'X -version', then for pkgtools, then for glibc, then for .... something else. You can change the order around to best fit your needs.
 
Old 12-04-2007, 02:51 AM   #6
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quote:
Originally Posted by Alien Bob View Post
Try
Code:
cat /etc/slackware-version
Other distros have similar files.

Eric
Works for Slackware (I guess, and unless the file is removed or altered), but not for all distributions. For some it may be missing, and for some it doesn't tell the whole truth - on Ubuntu, for example, the file is /etc/debian_version and on Gutsy it says lenny/sid. Ok, it's probably because Gutsy is based on that, but you can't really use it to determine your Ubuntu version..

Maybe the "fallback method" is the best there is, because as far as I can tell there is no solid solution. Each Linux operating system is built on a Linux kernel and a bunch of software, and none of them is branded to tell which distribution it is that they are on.

Other methods to add to the "test list" could be reading bootloader configuration (but it may need root privileges, and you'd need to know which bootloader is used, and the config could still be altered so it doesn't say "Slackware 12 kernel ....") or reading 'version' from proc:
Code:
cat /proc/version
Not sure how easily that information is changed by an admin, though.
 
Old 12-04-2007, 09:33 AM   #7
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,443

Original Poster
Rep: Reputation: 73
Thanks for all the responses! /etc/slackware-version is the simple thing I couldn't remember. I had already tested uname and /proc/version, but they only give hints that it might be Slackware. "X -version" seems to work great as well.

I agree that the approach should have fallbacks. Probably the first three I would test for (in order) are

/etc/slackware-version
X -version
/var/log/packages/pkgtools-12.0.0-noarch-4 (and so on for each version)

thanks again!
 
Old 12-04-2007, 10:02 AM   #8
cowyn
Member
 
Registered: Oct 2006
Location: Hangzhou, China
Distribution: Slackware
Posts: 49

Rep: Reputation: 15
just a simple example:
Code:
if [ -f /etc/slackware-version ]; then
    DISTRO=slackware
    VERSION=`awk '{print $2}' /etc/slackware-version`
fi
 
Old 12-04-2007, 07:02 PM   #9
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
This is what I use in my scripts to determine distribution, but as already mentioned, it won't always be 100% accurate.

Code:
if [ -f /etc/*release ]; then
  DISTRO="$(cat /etc/*release)"
elif [ -f /etc/*version ]; then
  DISTRO="$(cat /etc/*version)"
else
  DISTRO="Unable to Determine"
fi
As far as I am aware, there is no way to tell what distribution your software is running on with perfect accuracy. The best you can do is little more than an educated guess.
 
Old 12-06-2007, 04:24 AM   #10
msantinho
Member
 
Registered: Oct 2005
Location: Lisbon
Distribution: Slackware
Posts: 56

Rep: Reputation: 17
Just a suggestion: get Webmin's source and look at the 'os_list.txt' file.
They have done a nice (in my oppinion) job to compile a list of ways to determine OSs versions.
 
Old 12-06-2007, 11:11 AM   #11
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,443

Original Poster
Rep: Reputation: 73
Thanks again for the replies. I got webmin's list. It does seem to be a good reference, but it isn't a script itself. I can just pick and choose some of those references in the file to make a script I need.

As said before, however, I still think it is a good idea to have fallback checks, so I think the references in this text file should be combined with some of the previous suggestions.
 
Old 12-12-2007, 12:17 AM   #12
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
For LSB compliant distros there is lsb_release.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine XFreeX86 version soscalgary Slackware 2 10-05-2006 10:46 PM
I would like to be able to determine my kernel version. Gueron Linux - Newbie 3 10-10-2005 02:24 PM
Determine version of Linux OS? amiableboy Linux - Newbie 2 07-21-2005 04:16 AM
determine kernel version linuxmandrake Mandriva 1 05-28-2005 05:38 AM
How to determine Kernel version stonesino Linux - General 2 03-13-2004 01:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration