Browse Source

more sparation and retrieve some informations about the available cpus and their capabilities. If we are on a GNU system this is done via nprocs and on a Linux via lscpu, if we are a GNU/Linux both are used, which is not the best way from a performance point of view, but it show that execution based on my classes works.

master
Georg Hopp 12 years ago
parent
commit
bbbd9408d7
  1. 3
      classes.sh
  2. 32
      cpu_information.sh
  3. 102
      dist_information.sh
  4. 9
      gnu_information.sh
  5. 23
      host_information.sh
  6. 18
      interface_information.sh
  7. 9
      run.sh
  8. 134
      system_information.sh
  9. 4
      utils.sh

3
classes.sh

@ -16,7 +16,8 @@ has_class() {
exit 1 exit 1
fi fi
test "${CLASSES}" != "${CLASSES%${1}*}"
local CHECK=" ${CLASSES}"
test "${CHECK}" != "${CHECK% ${1} *}"
} }
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

32
cpu_information.sh

@ -0,0 +1,32 @@
#!/bin/dash
. ./utils.sh
include_once classes.sh
gather_cpu_info() {
[ -z "${NCPUS}" ] || return
has_class "GNU" && {
export NCPUS=$(${NPROC})
}
has_class "Linux" && {
eval $(${LSCPU} | ${AWK} -F: '
{ sub(/^ */,"",$2) }
/Byte Order/ {
sub(/ /,"_",$2);
print "export BYTE_ORDER=\"" $2 "\";"
}
/CPU op-mode/ {
sub(/,/,"",$2);
print "export OP_MODES=\"" $2 "\";"
}
/CPU(s):/ { print "export NCPUS=" $2 ";" }
/Virtualization/ { print "export CPU_VIRT=\"" $2 "\";" }')
}
CLASSES="${CLASSES}${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES} "
CLASSES="$(${ECHO} "${CLASSES}" | "${SED}" 's/ \+/ /g')"
}
# vim: set ts=4 sw=4:

102
dist_information.sh

@ -0,0 +1,102 @@
#!/bin/dash
. ./utils.sh
##
# if we are on a linux try to figure out wich distribution we are
# running.
# First look what kind of realease file we have:
#
# 00 01 - Novell SuSE ---> /etc/SuSE-release
# 00 02 - Red Hat ---> /etc/redhat-release, /etc/redhat_version
# 00 04 - Fedora ---> /etc/fedora-release
# 00 08 - Slackware ---> /etc/slackware-release, /etc/slackware-version
# 00 10 - Debian ---> /etc/debian_release, /etc/debian_version
# 00 20 - Mandrake ---> /etc/mandrake-release
# 00 40 - Yellow dog ---> /etc/yellowdog-release
# 00 80 - Sun JDS ---> /etc/sun-release
# 01 00 - Solaris/Sparc ---> /etc/release
# 02 00 - Gentoo ---> /etc/gentoo-release
#
# Here I follow a pessimistic way because I prefere to have no
# identification at all over a wrong one...so I check for all these files.
# If I can't find any or find multiple of them I assume this system
# as unidentified. Anyway when I found one I still check the content...
# Here I need some help as I don't know the valid content of these files.
# For now I assume that at least the name of the distribution is in
# the file.
#
gather_dist_info() {
[ -z "${DIST}" ] || return
case "${OS}" in
*Linux*)
local SUSE=1
local REDHAT=2
local FEDORA=4
local SLACKWARE=8
local DEBIAN=16
local MANDRAKE=32
local YELLOWDOG=64
local SUNJDS=128
local GENTOO=256
local SOLARIS=512
local LAST=${SOLARIS}
local CHK=$((SUSE|REDHAT|FEDORA|SLACKWARE|DEBIAN|MANDRAKE|\
YELLOWDOG|SUNJDS|GENTOO|SOLARIS))
eval local FILES_${SUSE}=\'/etc/SuSE-release\'
eval local FILES_${REDHAT}=\'/etc/redhat-release /etc/redhat_version\'
eval local FILES_${FEDORA}=\'/etc/fedora-release\'
eval local FILES_${SLACKWARE}=\'/etc/slackware-release /etc/slackware-version\'
eval local FILES_${DEBIAN}=\'/etc/debian_release /etc/debian_version\'
eval local FILES_${MANDRAKE}=\'/etc/mandrake-release\'
eval local FILES_${YELLOWDOG}=\'/etc/yellowdog-release\'
eval local FILES_${SUNJDS}=\'/etc/sun-release\'
eval local FILES_${GENTOO}=\'/etc/gentoo-release\'
eval local FILES_${SOLARIS}=\'/etc/release\'
local CUR=1
while [ ${CUR} -le ${LAST} ]
do
local DIR
eval local FILES=\"\${FILES_${CUR}}\"
for DIR in ${FILES}
do
[ -f ${DIR} ] || CHK=$((CHK&~CUR))
done
CUR=$((CUR*2))
done
DIST="Unknown"
[ ${CHK} -eq ${SUSE} ] && DIST="Suse"
[ ${CHK} -eq ${REDHAT} ] && DIST="Redhat"
[ ${CHK} -eq ${FEDORA} ] && DIST="Fedora"
[ ${CHK} -eq ${SLACKWARE} ] && DIST="Slakware"
[ ${CHK} -eq ${DEBIAN} ] && DIST="Debian"
[ ${CHK} -eq ${MANDRAKE} ] && DIST="Mandrake"
[ ${CHK} -eq ${YELLOWDOG} ] && DIST="Yellowdog"
[ ${CHK} -eq ${SUNJDS} ] && DIST="Sun"
[ ${CHK} -eq ${GENTOO} ] && DIST="Gentoo"
[ ${CHK} -eq ${SOLARIS} ] && DIST="Solaris"
if [ 'Unknown' != "${DIST}" ]
then
eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
fi
CLASSES="${CLASSES}${DIST} ";;
*)
DIST="${OS}"
esac
export DIST CLASSES
}
# vim: set ts=4 sw=4:

9
gnu_information.sh

@ -1,16 +1,15 @@
#!/bin/dash #!/bin/dash
## ##
# This creates function that will gather some system informations
# and propagate them as environment variables.
# The GNU way for more information
# #
. ./utils.sh . ./utils.sh
include_once system_information.sh
echo "foo ${NPROC}"
CPUS=$(${NPROC})
gather_gnu_information() {
export CPUS=$(${NPROC})
export CLASSES="${CLASSES}${CPUS}cpus " export CLASSES="${CLASSES}${CPUS}cpus "
}
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

23
host_information.sh

@ -0,0 +1,23 @@
#!/bin/dash
. ./utils.sh
##
# start guessing the system type via uname and export it.
#
gather_host_info() {
[ -z "${OS}" ] || return
OS="$(${UNAME} -o)"
KERNEL="$(${UNAME} -s)"
VERSION="$(${UNAME} -r)"
PLATFORM="$(${UNAME} -m)"
HOSTNAME="$(${UNAME} -n)"
GNU="$([ "${OS%GNU*}" != ${OS} ] && echo "GNU")"
CLASSES="${OS}\n${GNU}\n${KERNEL}\n${VERSION}\n${PLATFORM}\n${HOSTNAME}"
CLASSES="$(${ECHO} -e "${CLASSES}" | ${SORT} -u | ${TR} "\n" " ")"
export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES
}
# vim: set ts=4 sw=4:

18
interface_information.sh

@ -13,16 +13,18 @@
# how to retrieve this information on other systems. # how to retrieve this information on other systems.
# This also exports the environment variables. # This also exports the environment variables.
# #
get_interface_data() {
gather_interface_info() {
[ -z "${NINTERFACES}" ] || return
local NO=1 local NO=1
if [ ${IP} ] if [ ${IP} ]
then then
get_interface_data_ip
gather_if_info_ip
else else
if [ ${IFCONFIG} ] if [ ${IFCONFIG} ]
then then
get_interface_data_ifconfig
gather_if_info_ifconfig
else else
${LOGGER} -p local0.warn 'Found no way to retrieve interface information.' ${LOGGER} -p local0.warn 'Found no way to retrieve interface information.'
fi fi
@ -41,7 +43,7 @@ get_interface_data() {
## ##
# get the interface information from the ip tool # get the interface information from the ip tool
# #
get_interface_data_ip() {
gather_if_info_ip() {
eval $(${IP} -o link | ${AWK} '{ eval $(${IP} -o link | ${AWK} '{
sub(/:/,"",$1); sub(/:/,"",$1);
no=$1; no=$1;
@ -92,7 +94,7 @@ get_interface_data_ip() {
## ##
# get interface data via the ifconfig tool # get interface data via the ifconfig tool
# #
get_interface_data_ifconfig() {
gather_if_info_ifconfig() {
eval $(${IFCONFIG} -a | ${AWK} ' eval $(${IFCONFIG} -a | ${AWK} '
/ether/ { mac=$2 } /ether/ { mac=$2 }
/inet / { ipv4=ipv4 $2 " " } /inet / { ipv4=ipv4 $2 " " }
@ -121,10 +123,4 @@ get_interface_data_ifconfig() {
}') }')
} }
##
# autorun this if sourced.
#
[ -z "${NINTERFACES}" ] && get_interface_data
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

9
run.sh

@ -10,10 +10,12 @@
# #
. ./utils.sh . ./utils.sh
include_once system_information.sh include_once system_information.sh
include_once interface_information.sh
include_once network_tools.sh include_once network_tools.sh
gather_information
## ##
# report everysthing # report everysthing
# #
@ -24,7 +26,10 @@ ${PRINTF} "%15s : %s\n" "VERSION" "${VERSION}"
${PRINTF} "%15s : %s\n" "PLATFORM" "${PLATFORM}" ${PRINTF} "%15s : %s\n" "PLATFORM" "${PLATFORM}"
${PRINTF} "%15s : %s\n" "DIST" "${DIST}" ${PRINTF} "%15s : %s\n" "DIST" "${DIST}"
${PRINTF} "%15s : %s\n" "HOSTNAME" "${HOSTNAME}" ${PRINTF} "%15s : %s\n" "HOSTNAME" "${HOSTNAME}"
${PRINTF} "%15s : %s\n" "CPUS" "${CPUS}"
${PRINTF} "%15s : %s\n" "# CPUS" "${NCPUS}"
${PRINTF} "%15s : %s\n" "BYTE_ORDER" "${BYTE_ORDER}"
${PRINTF} "%15s : %s\n" "OP_MODES" "${OP_MODES}"
${PRINTF} "%15s : %s\n" "CPU_VIRT" "${CPU_VIRT}"
${PRINTF} "%15s : %s\n" "# INTERFACES" "${NINTERFACES}" ${PRINTF} "%15s : %s\n" "# INTERFACES" "${NINTERFACES}"
NO=1 NO=1

134
system_information.sh

@ -1,133 +1,17 @@
#!/bin/dash #!/bin/dash
##
# This creates function that will gather some system informations
# and propagate them as environment variables.
#
. ./utils.sh . ./utils.sh
##
# start guessing the system type via uname and export it.
#
get_host_info() {
OS="$(${UNAME} -o)"
KERNEL="$(${UNAME} -s)"
VERSION="$(${UNAME} -r)"
PLATFORM="$(${UNAME} -m)"
HOSTNAME="$(${UNAME} -n)"
CLASSES="$(${ECHO} -e "${OS}\n${KERNEL}\n${VERSION}\n${PLATFORM}\n${HOSTNAME}" |\
${SORT} -u | ${TR} "\n" " ")"
include_once host_information.sh
include_once dist_information.sh
include_once cpu_information.sh
include_once interface_information.sh
export OS KERNEL VERSION PLATFORM HOSTNAME CLASSES
gather_information() {
gather_host_info
gather_dist_info
gather_cpu_info
gather_interface_info
} }
##
# if we are on a linux try to figure out wich distribution we are
# running.
# First look what kind of realease file we have:
#
# 00 01 - Novell SuSE ---> /etc/SuSE-release
# 00 02 - Red Hat ---> /etc/redhat-release, /etc/redhat_version
# 00 04 - Fedora ---> /etc/fedora-release
# 00 08 - Slackware ---> /etc/slackware-release, /etc/slackware-version
# 00 10 - Debian ---> /etc/debian_release, /etc/debian_version
# 00 20 - Mandrake ---> /etc/mandrake-release
# 00 40 - Yellow dog ---> /etc/yellowdog-release
# 00 80 - Sun JDS ---> /etc/sun-release
# 01 00 - Solaris/Sparc ---> /etc/release
# 02 00 - Gentoo ---> /etc/gentoo-release
#
# Here I follow a pessimistic way because I prefere to have no
# identification at all over a wrong one...so I check for all these files.
# If I can't find any or find multiple of them I assume this system
# as unidentified. Anyway when I found one I still check the content...
# Here I need some help as I don't know the valid content of these files.
# For now I assume that at least the name of the distribution is in
# the file.
#
get_dist_info() {
[ -z "${KERNEL}" ] && get_host_info
if [ "Linux" = "${KERNEL}" ]
then
local SUSE=1
local REDHAT=2
local FEDORA=4
local SLACKWARE=8
local DEBIAN=16
local MANDRAKE=32
local YELLOWDOG=64
local SUNJDS=128
local GENTOO=256
local SOLARIS=512
local LAST=${SOLARIS}
local CHK=$((SUSE|REDHAT|FEDORA|SLACKWARE|DEBIAN|MANDRAKE|\
YELLOWDOG|SUNJDS|GENTOO|SOLARIS))
eval local FILES_${SUSE}=\'/etc/SuSE-release\'
eval local FILES_${REDHAT}=\'/etc/redhat-release /etc/redhat_version\'
eval local FILES_${FEDORA}=\'/etc/fedora-release\'
eval local FILES_${SLACKWARE}=\'/etc/slackware-release /etc/slackware-version\'
eval local FILES_${DEBIAN}=\'/etc/debian_release /etc/debian_version\'
eval local FILES_${MANDRAKE}=\'/etc/mandrake-release\'
eval local FILES_${YELLOWDOG}=\'/etc/yellowdog-release\'
eval local FILES_${SUNJDS}=\'/etc/sun-release\'
eval local FILES_${GENTOO}=\'/etc/gentoo-release\'
eval local FILES_${SOLARIS}=\'/etc/release\'
local CUR=1
while [ ${CUR} -le ${LAST} ]
do
local DIR
eval local FILES=\"\${FILES_${CUR}}\"
for DIR in ${FILES}
do
[ -f ${DIR} ] || CHK=$((CHK&~CUR))
done
CUR=$((CUR*2))
done
DIST="Unknown"
[ ${CHK} -eq ${SUSE} ] && DIST="Suse"
[ ${CHK} -eq ${REDHAT} ] && DIST="Redhat"
[ ${CHK} -eq ${FEDORA} ] && DIST="Fedora"
[ ${CHK} -eq ${SLACKWARE} ] && DIST="Slakware"
[ ${CHK} -eq ${DEBIAN} ] && DIST="Debian"
[ ${CHK} -eq ${MANDRAKE} ] && DIST="Mandrake"
[ ${CHK} -eq ${YELLOWDOG} ] && DIST="Yellowdog"
[ ${CHK} -eq ${SUNJDS} ] && DIST="Sun"
[ ${CHK} -eq ${GENTOO} ] && DIST="Gentoo"
[ ${CHK} -eq ${SOLARIS} ] && DIST="Solaris"
if [ 'Unknown' != "${DIST}" ]
then
eval ${GREP} -iq ${DIST} \${FILES_${CHK}} || DIST="Unknown"
fi
CLASSES="${CLASSES}${DIST} "
else
DIST="${OS}"
fi
export DIST CLASSES
}
##
# autorun this if sourced.
#
[ -z "${DIST}" ] && get_dist_info
case "${OS}" in
GNU/*)
include_once gnu_information.sh;;
esac
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:

4
utils.sh

@ -88,16 +88,18 @@ then
[ -z "${UNAME}" ] && UNAME="$(${WHICH} uname)" [ -z "${UNAME}" ] && UNAME="$(${WHICH} uname)"
[ -z "${GREP}" ] && GREP="$(${WHICH} grep)" [ -z "${GREP}" ] && GREP="$(${WHICH} grep)"
[ -z "${AWK}" ] && AWK="$(${WHICH} awk)" [ -z "${AWK}" ] && AWK="$(${WHICH} awk)"
[ -z "${SED}" ] && SED="$(${WHICH} sed)"
[ -z "${ECHO}" ] && ECHO="$(${WHICH} echo)" [ -z "${ECHO}" ] && ECHO="$(${WHICH} echo)"
[ -z "${SORT}" ] && SORT="$(${WHICH} sort)" [ -z "${SORT}" ] && SORT="$(${WHICH} sort)"
[ -z "${TR}" ] && TR="$(${WHICH} tr)" [ -z "${TR}" ] && TR="$(${WHICH} tr)"
[ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)" [ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)"
[ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)" [ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)"
[ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)" [ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)"
[ -z "${LSCPU}" ] && LSCPU="$(${WHICH} lscpu)"
[ -z "${IP}" ] && IP="$(${WHICH} ip)" [ -z "${IP}" ] && IP="$(${WHICH} ip)"
[ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)" [ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)"
export WHICH UNAME GREP AWK ECHO SORT TR PRINTF LOGGER IP IFCONFIG
export WHICH UNAME GREP AWK SED ECHO SORT TR PRINTF LOGGER NPROC LSCPU IP IFCONFIG
fi fi
# vim: set ts=4 sw=4: # vim: set ts=4 sw=4:
Loading…
Cancel
Save