Register
It is currently Fri Aug 01, 2014 10:32 pm

Script that prints the kernel compilation timestamp


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Tue Apr 21, 2009 10:23 am   

Joined: Tue Apr 21, 2009 10:17 am
Posts: 3
Hi,
I need a script that prints the kernel compilation time stamp.
I've tried using the uname
Code:
uname -v
command but I'm not sure if this is the correct approach.
Any suggestions ?


Top
 Profile  
 PostPosted: Tue Apr 21, 2009 11:28 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Well it's about as close as you can get :)

I guess if you want to reformat the output something like this might be used.
I do believe you should be able to convert it using date, but I didn't feel like studying the manpage today :P
Code:
#!/bin/bash
stamp=$(uname -v)
tmp="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
x=1
for i in $tmp; do
   month=$(echo $stamp | cut -d' ' -f3)
   if [ $i == $month ]; then
      if [ $x -lt 10 ]; then tmp2="0$x"; fi
      day=$(echo $stamp | cut -d' ' -f4)
      time=$(echo $stamp | cut -d' ' -f5)
      year=$(echo $stamp | cut -d' ' -f7)
   fi
   ((x++))
done
month=$tmp2
echo ${year}-${month}-${day} ${time}


ps. this is quick and dirty :P ds.

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Tue Apr 21, 2009 12:01 pm   

Joined: Tue Apr 21, 2009 10:17 am
Posts: 3
that looks ok , but I'm also wondering if using the
Code:
uname
is the correct way of determining the time when the kernel was compiled


Top
 Profile  
 PostPosted: Tue Apr 21, 2009 2:30 pm   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Well the only other way I can think of is checking the vmlinuz file too see when it was created... but that ain't all that reliable... if you were to move or copy the file the stamp might change.

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Wed Apr 22, 2009 9:21 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
You could get it from /proc/version, but that should be the same stamp you'd get from 'uname -v'

Code:
$ grep -Eo '[a-zA-Z]{3}.[a-zA-Z]{3}.[0-9]{1,2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[a-zA-Z]{3}.[0-9]{4}' /proc/version
Tue Jun 10 11:56:48 CDT 2008

$ uname -a | grep -Eo '[a-zA-Z]{3}.[a-zA-Z]{3}.[0-9]{1,2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[a-zA-Z]{3}.[0-9]{4}'
Tue Jun 10 11:56:48 CDT 2008

$ uname -v | grep -Eo '[a-zA-Z]{3}.[a-zA-Z]{3}.[0-9]{1,2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[a-zA-Z]{3}.[0-9]{4}'
Tue Jun 10 11:56:48 CDT 2008


I'm sure that regex could be simplified... I'm NOT sure that it will get every possible time stamp... But you can see from here that uname and /proc/version should both have the same date for the kernel build, and this should be the accurate kernel build date.

Hope this helps!
-J


Top
 Profile YIM  
 PostPosted: Wed Apr 22, 2009 12:03 pm   

Joined: Tue Apr 21, 2009 10:17 am
Posts: 3
thanks that works quite fine.
offtopic : how can one compare two diferent dates
Code:
adate=$(grep -Eo '[a-zA-Z]{3}.[a-zA-Z]{3}.[0-9]{1,2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[a-zA-Z]{3}.[0-9]{4}' /proc/version)
pastdate=SixDaysAgo=$(date --date='14 days ago')

these are the two dates i want to do something like
Code:
if (adate-pastdate>14) then print"two weeks have passes"


Top
 Profile  
 PostPosted: Thu Apr 23, 2009 8:03 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
You convert the time to epoch time ofcourse :)
Then subtract 14*86400 from the epoch time and you get a value 14 days earlier :)

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Tue May 05, 2009 7:15 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
/me hugs epoch time :)


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP