954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get installed kernels using python code

Hi, I want to get installed Xen kernels & initrds in my computer using a python code. When I do a ls /boot I get the following results.

config-2.6.26-2-686
config-2.6.26-2-xen-686
grub
initrd.img-2.6.26-2-686
initrd.img-2.6.26-2-686.bak
initrd.img-2.6.26-2-xen-686
initrd.img-2.6.26-2-xen-686.bak
System.map-2.6.26-2-686
System.map-2.6.26-2-xen-686
vmlinuz-2.6.26-2-686
vmlinuz-2.6.26-2-xen-686
xen-3.2-1-i386.gz

and what I want is "vmlinuz-2.6.26-2-xen-686" & "initrd.img-2.6.26-2-xen-686". We can get the results using lot of string processing but I need a simple way to do this.
Thank You.

mwaidyanatha
Newbie Poster
1 post since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

You can start with

import os
L = [x for x in os.listdir("/boot") if "-xen-" in x]
print(L)
Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: