S.K.I.M. - SuSE Kernel Installed Modules; A bash script file intended to be a replacement for the terminal command lsmod. It provides an alphabetized kernel module listing which can also be saved as a text file into Documents folder, as selected at run time of the bash script. Here is what the text listing looks like using skim (the terminal command Less is used to display text):
http://thumbnails43.imagebam.com/14415/ec5972144149952.jpg](ImageBam)
In order to obtain S.K.I.M., please copy and paste the following text in the code field into your favorite text editor:
#!/bin/bash
#: Title : skim
#: Date Created: Sun Aug 7 13:03:13 CDT 2011
#: Last Edit : Mon Aug 8 18:35:13 CDT 2011
#: Author : James D. McDaniel
#: Version : 1.00
#: Description : Provides Kernel Module Information
#: Options : skim -m -h -r --help]
TITLE="S.K.I.M. - SuSE Kernel Installed Modules"
declare -a arr
declare -a lin
#
# Where do you want to create your module text files?
#
mod_file_location=~/Documents
#
# skim creates a text file, do you want it removed on exit?
# remove_mod_text_file_on_exit=false <OR> remove_mod_text_file_on_exit=true
# the skim -r startup option can override this selection
#
remove_mod_text_file_on_exit=true
#
# Written for the openSUSE forums on Monday August 8, 2011
#
#
# Copy and Paste the text of this script into a text editor and save
# it as the file skim in your home area bin folder (~/bin/skim).
# This script must be marked executable to be used. Please run
# the following Terminal command: chmod +x ~/bin/skim
# To use skim, open a terminal session and type: skim or skim -h for help
#
# S.K.I.M. function Blocks ****************************************************
#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "S.K.I.M. is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}
#
# S.K.I.M. Help Display Function
#
function help {
tput clear
cat << EOFHELP
$TITLE
S.K.I.M. requires no Startup Options, But if you use them, your choices are:
skim ; Shows Listed Modules
skim -r ; Shows Listed Modules & Saves Text Report
skim -m ; Shows Skim Menu
skim -m -r ; Shows Skim Menu & Saves Text Report
skim -h ; Shows this help
skim --help ; Shows this help
EOFHELP
echo -n " Press <enter> to read the GPL Statement for S.K.I.M."
read CHOICE
tput clear
show_gpl
exit 0
}
#
# Locate next Substring by space seperator in a long string
# Start looking at character position $1 in string $2
# Return location of next space, between sub-strings
#
function sub_string {
counter=$1
start=$2
num2=${#start}
while $(( counter )) -lt $(( num2 + 1 )) ] ; do
temp="${start:$(($counter)):1}"
if $temp != " " ]] ; then
let counter=counter+1
else
return ${counter}
fi
done
return ${counter}
}
#
# Common S.K.I.M. Exit Tasks
#
function exit_skim {
tput clear
echo $TITLE " - Total of $a Modules Found"
show_gpl
if $remove_mod_text_file_on_exit ; then
rm $mod_file_name
else
echo "Your Kernel Module Info was saved in: "
echo
echo $mod_file_name
fi
echo
}
# S.K.I.M. Error & Help *******************************************************
#
# Determine if the folder mod_file_location exists
#
if ! -d "$mod_file_location" ]] ; then
echo "The Document Folder: $mod_file_location, does not exist!"
echo "Please create or change this folder name and start $(basename $0) again."
echo
exit 1
fi
#
# Display S.K.I.M. Help if requested.
#
menu=false
case "$1" in
-h|--help) help ;;
-m|-M) menu=true ;;
-r|-R) remove_mod_text_file_on_exit=false ;;
esac
case "$2" in
-r|-R) remove_mod_text_file_on_exit=false ;;
-m|-M) menu=true ;;
esac
# S.K.I.M. Create Module Text File ********************************************
#
# Sets the name of the text file where your module info is saved
#
ext=$(date +%m%d%y.%H%M%S)
mod_file_name=$mod_file_location"/"Kernel_Module_Listing"."$ext".txt"
#
# This reads in the module list, then sorts it by to your text file as named above
#
a=0
sort /proc/modules -o $mod_file_name
while read line; do a=$(($a+1)); arr$a]=$a") "$line; done < $mod_file_name
#
# We now create a header for the modul listing text file
#
echo $TITLE " - Total of $a Modules Loaded" > $mod_file_name
echo >> $mod_file_name
echo "Name = Shows the internal name of the kernel module installed." >> $mod_file_name
echo "Size = Refers to the total memory size used by the module, in bytes." >> $mod_file_name
echo "Ins = Lists how many instances of the module are currently loaded. '0' means unloaded." >> $mod_file_name
echo "Requires = Lists required module(s) that must be present in order to function properly." >> $mod_file_name
echo >> $mod_file_name
echo "Num Name Size Ins Requires" >> $mod_file_name
#
# We serach through each line of text for an installed module,
# finding the space in order to space out like items into columns
#
pointer=0
while $pointer -lt $((a+1)) ]] ; do
pos=0
ind=0
while $pos -lt 8 ]] ; do
sub_string $((ind)) "${arr$pointer]}"
nxt=$?
lin$pos]=${arr$pointer]:$((ind)):$((nxt-ind))}
let pos=pos+1
let ind=nxt+1
done
#
# This sets the width for each column set
#
pos=0
# This is the default Tab width for module dependancies
area=80
while $pos -lt 5 ]] ; do
# The Module Number
if $pos -eq 0 ]] ; then
area=5
fi
# The module name
if $pos -eq 1 ]] ; then
area=23
fi
# The module memory size
if $pos -eq 2 ]] ; then
area=9
fi
# The module instance
if $pos -eq 3 ]] ; then
area=3
fi
# Output the item within the selected field
let spc=${#lin$pos]}
let tot=area-spc
echo -n ${lin$pos]} >> $mod_file_name
# Pad with spaces less item length per field width
cnt=0
while $cnt -lt $((tot+1)) ]] ; do
echo -n " " >> $mod_file_name
let cnt=cnt+1
done
let pos=pos+1
done
# Terminate the finished modulde text line when complete
echo >> $mod_file_name
let pointer=pointer+1
done
#
# S.K.I.M. Main Menu when a menu is requested. ********************************
#
while $menu ; do
tput clear
echo $TITLE " - Total of $a Modules Loaded"
echo
echo "1) View Your Module Listing with Viewer Less - Enter a Q to quit"
echo "2) Get Info On a Module (View Module Listing First for a Number)"
echo "Q) Quit $TITLE"
echo
echo -n "Please Make Your Selection: "
read -n1 CHOICE
#
# View Your Module Listing using Less
#
if $CHOICE == "1" ]] ; then
less $mod_file_name
fi
#
# Menu to request module name modinfo to be used
#
if $CHOICE == "2" ]] ; then
tput clear
echo $TITLE " - Total of $a Modules Loaded"
echo
echo -n "Enter Module Number for Information and press <enter> [1-$a]: "
read CHOICE
#
# Check the number entered as valid between 1 and maximum modules loaded
#
if $CHOICE =~ ^[0-9]+$ ]] ; then
if $CHOICE -le $a ]] && $CHOICE -gt 0 ]]; then
sub_string "0" "${arr$CHOICE]}"
loc1=$?
sub_string "$((loc1+1))" "${arr$CHOICE]}"
loc2=$?
cmd=${arr$CHOICE]:$((loc1+1)):$((loc2-loc1))}
echo
echo ${arr$CHOICE]}
echo
/sbin/modinfo $cmd
echo
echo -n "Press Any Key to Continue: "
read something
fi
fi
fi
#
# Exit S.K.I.M. program & output the GPL statement
#
if $CHOICE == [Qq] ]] ; then
exit_skim
exit 0
fi
done
#
# S.K.I.M. -m option was selected to be here **********************************
#
less $mod_file_name
exit_skim
exit 0
# End Of Script
Save the above script as the text file called skim into your ~/bin folder (/home/yourname/bin/skim). In order to use skim it must be marked executable. Open up a terminal session and run the following command:
chmod +x ~/bin/skim
To use skim, open up a terminal session and use one of the following startup options:
S.K.I.M. - SuSE Kernel Installed Modules
S.K.I.M. requires no Startup Options, But if you use them, your choices are (as shown by using skim -h):
skim ; Shows Listed Modules
skim -r ; Shows Listed Modules & Saves Text Report
skim -m ; Shows Skim Menu
skim -m -r ; Shows Skim Menu & Saves Text Report
skim -h ; Shows this help
skim --help ; Shows this help
The skim -m option starts a menu that allows you to view the module listing and to request modinfo for any installed module. Here is such an example:
S.K.I.M. - SuSE Kernel Installed Modules - Total of 85 Modules Loaded
Enter Module Number for Information and press <enter> [1-85]: 7
7) coretemp 6542 0 - Live 0xffffffffa00b8000
filename: /lib/modules/3.0.1-0.5-desktop/kernel/drivers/hwmon/coretemp.ko
license: GPL
description: Intel Core temperature monitor
author: Rudolf Marek <r.marek@assembler.cz>
srcversion: C4C170496F5A24372E34F70
depends:
vermagic: 3.0.1-0.5-desktop SMP preempt mod_unload modversions
Press Any Key to Continue:
When you elect to save the module listing ( skim -r <OR> skim -m -r ) the text file it is saved in the ~/Documents folder in the format: Module_Listing.080711.201729.txt and can be viewed at a later time if required. As always I want to hear any comments you may have about the usage of skim. When you read through this message thread, always look to the end for newer versions of skim, should they exist. Remember you can name skim anything you like should the cleverness of S.K.I.M. escape you.
Thank You,