Display “real” FreeBSD version

Typically when you want to find the current version of FreeBSD you type the following:

$ uname -r
10.3-RELEASE-p4

That’s great but it doesn’t tell the full story. If updates were made that do not affect the kernel, than it will not be reflected here. For instance, if the system had been upgraded to patch 12 I would not know that from looking at this. It makes it look like its only been updated to patch 4. Enter the “/usr/src/sys/conf/newvers.sh” file. This file gives a more clear picture of the system’s current state of affairs. I wrote a quick script that grabs the relevant info from this file and displays it similarly to the uname output.

#!/usr/local/bin/perl

use strict;
use warnings;

my $file = "/usr/src/sys/conf/newvers.sh";
my $cnt = 0;
my ($type, $rev, $branch);

open (FILE, "$file") or die "File $file does not exist!";
while (<FILE>) {
 chomp ($_);
     if ($_ =~ /^TYPE="(.*)?"/) {
         $type = $1;
         $cnt++;
     }
    if ($_ =~ /^REVISION="(.*)?"/ && $cnt == 1) {
         $rev = $1;
         $cnt++;
     }
     if ($_ =~ /^BRANCH="(.*)?"/ && $cnt == 2) {
         $branch = $1;
     }
}
close (FILE);

print "$type $rev $branch\n";

I put this script in /usr/local/sbin/hostver on all the systems I administer.

$ hostver
FreeBSD 10.3 RELEASE-p12

Now I always know the current patch level of the system. There are other ways to get this info (freebsd-version) but this works fine for me.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s