1

I want to get the last update date of kernel in AIX & Solaris.

For Linux, the command is:

rpm -qa --last | grep kernel-`uname -r` | sed 's/^k.*\s\s//'

For this command I'm getting the output:

Wed 29 Nov 2017 03:26:48 PM EST

I need same replacement for AIX & Solaris as well.

I'm trying to execute this command for AIX, but it's not sophisticated proper output what I need:

lslpp -ha bos.adt.base | grep COMPLETE | sed 's/^k.*\s\s//'
Return Code: 0,                   6.1.1.0   COMMIT       COMPLETE     09/16/14     13:49:31    
                  6.1.1.0   APPLY        COMPLETE     09/16/14     13:49:31    
                 6.1.8.16   COMMIT       COMPLETE     09/16/14     13:59:18    
                 6.1.8.16   APPLY        COMPLETE     09/16/14     13:55:32    
                 6.1.9.30   COMMIT       COMPLETE     07/02/15     16:36:49    
                 6.1.9.30   APPLY        COMPLETE     07/02/15     16:33:22    
                 6.1.9.45   COMMIT       COMPLETE     09/04/15     15:45:19    
                 6.1.9.45   APPLY        COMPLETE     09/04/15     15:45:09    
                6.1.9.101   APPLY        COMPLETE     09/14/17     16:44:44    
                  6.1.1.0   COMMIT       COMPLETE     09/16/14     13:49:36    
                  6.1.1.0   APPLY        COMPLETE     09/16/14     13:49:36    
                 6.1.8.16   COMMIT       COMPLETE     09/16/14     13:59:18    
                 6.1.8.16   APPLY        COMPLETE     09/16/14     13:55:32    
                 6.1.9.30   COMMIT       COMPLETE     07/02/15     16:36:49    
                 6.1.9.30   APPLY        COMPLETE     07/02/15     16:33:23    
                 6.1.9.45   COMMIT       COMPLETE     09/04/15     15:45:19    
                 6.1.9.45   APPLY        COMPLETE     09/04/15     15:45:10    
                6.1.9.101   APPLY        COMPLETE     09/14/17     16:44:45     

Or else I need only last line of above output.

  • What's the point of the last update date? Updating a 6-year-old kernel to a 5-year-old kernel last week doesn't mean the kernel is current. Either the version is up-to-date or it's not - when it was updated is irrelevant. – Andrew Henle Mar 7 '18 at 10:56
  • 1
    @AndrewHenle not necessarily irrelevant. if the machine or an application running on it is crashing in obscure circumstances and your logs show it only started happening after the kernel was upgraded from an ancient version to a slightly less ancient version, that's a pretty good indicator that it might be the kernel at fault. If the crash was happening before and after the kernel upgrade, it's unlikely to be implicated. – cas Mar 7 '18 at 11:21
  • @cas True, but if that's the reason for this question, it's on the way towards being an XY problem then, no? Hence the reasone I asked What's the point of the last update date? – Andrew Henle Mar 7 '18 at 12:03
  • @AndrewHenle My point was that it doesn't matter WHY the OP wants this information, it's not up to us here to judge whether it's useful or not. – cas Mar 7 '18 at 12:08
2

For the AIX part, instead of hard-coding the bos.adt.base fileset, and instead of asking for all of the updates -- applies and commits -- but instead just the commits, I would ask for the history of the fileset that owns the /unix symlink (which points to the kernel):

lslpp -q -c -h -Or $(lslpp -q -c -w /unix | cut -d: -f2) | tail -1 | cut -d: -f7-8

In pieces, that's:

  • -q -- don't print column headings
  • -c -- print output colon-delimited (easier to parse)
  • -h -- fileset history
  • -w -- which fileset owns the given file
  • -Or -- only need one set; root or usr works here

From the inside out, we get the fileset name from lslpp ... -w and then ask for the history of that fileset; that's then piped to tail to get the last line (assumed to be the most recent), and then to cut to pull out the date and time fields.

For the Solaris part, perhaps the most recently applied patch to the kernel would suffice?

nawk -F: '/^PATCH_INFO/ { sub(" From", ""); print $2":"$3":"$4; }' \
  /var/sadm/pkg/SUNWckr/pkginfo | 
    sort -k6n | tail -1
1

On Solaris, you'll see the kernel patch installed by running: uname -v | awk -F_ '{print $2}'

If you then run: ls -lat /var/sadm/patch |grep <patch>

You'll see the timestamp of when it was installed. There will also be logs in that directory if you want further information.

  • /var/sadm/patch will only be present on Solaris 10 and earlier, on Solaris 11.x you'll need to use pkg info system/kernel instead. – alanc Mar 8 '18 at 16:50
0

You can get the last line of any output by piping it to tail -1. Try this:

lslpp -ha bos.adt.base | sed -n '/COMPLETE/ s/^k.*\s\s//p' | tail -1

I've also folded the grep command into the sed command - it wasn't doing anything that sed can't do itself.

NOTE: I'm not familiar with the AIX lslpp command, so I'm just assuming it's the right tool to use for this job, and that you've used the most appropriate options with it. It may be worth reading the man page to see if there are better ways of using it to get what you want.

  • btw, too bad about the weird MM/DD/YY date format. if it was ISO-8601 standard YYYY-MM-DD, it could easily be sorted. – cas Mar 7 '18 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.