From afaba612056ad1311a88e6295e33bbf8dbffc683 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Sun, 16 Mar 2014 11:12:00 +0000 Subject: [PATCH] add file to gather further system information the gnuish way...for now get the number of cpus --- cf-engine-classes.txt | 64 +++++++++++++++++++++++++++++++++++++++++++ classes.sh | 22 +++++++++++++++ gnu_information.sh | 16 +++++++++++ run.sh | 8 ++++-- system_information.sh | 5 ++++ test.sh | 3 ++ utils.sh | 18 ++++++++---- 7 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 cf-engine-classes.txt create mode 100755 classes.sh create mode 100755 gnu_information.sh create mode 100755 test.sh diff --git a/cf-engine-classes.txt b/cf-engine-classes.txt new file mode 100644 index 0000000..3ba1ecd --- /dev/null +++ b/cf-engine-classes.txt @@ -0,0 +1,64 @@ + 127_0_0_1 + 192_168_120_40 + 2001_4ba0_ffff_138_1__400 +64_bit +8_cpus +?Day15 +?Evening +?GMT_Hr17 +?Hr18 +?Hr18_Q2 +?Lcycle_1 +?March +?Min15_20 +?Min17 +PK_MD5_1cc0a2b13599f57ebb17df5abdc45ae1 +?Q2 +?Saturday +?Yr2014 +agent +any +cfengine +cfengine_3 +cfengine_3_5 +cfengine_3_5_3 +community_edition +compiled_on_linux_gnu +cpu0_high +cpu1_high +cpu2_high +cpu3_high +cpu_high +diskfree_high_normal +entropy_misc_in_low +entropy_misc_out_low +entropy_postgresql_in_low +entropy_postgresql_out_low + fe80__14d8_4dff_fed7_9c59 +gentoo +inform_mode +ipv4_127 +ipv4_127_0 +ipv4_127_0_0 +ipv4_127_0_0_1 +ipv4_192 +ipv4_192_168 +ipv4_192_168_120 +ipv4_192_168_120_40 +ldap_out_high + linux + linux_3_12_8_hardened_r1 + linux_x86_64 + linux_x86_64_3_12_8_hardened_r1 + linux_x86_64_3_12_8_hardened_r1__4_SMP_Tue_Mar_4_17_38_20_CET_2014 +loadavg_low +localhost + mac_16_d8_4d_d7_9c_59 +net_iface_eth0 +net_iface_lo +rootprocs_high +ssh_in_high +test +users_high +verbose_mode + x86_64 diff --git a/classes.sh b/classes.sh new file mode 100755 index 0000000..0629989 --- /dev/null +++ b/classes.sh @@ -0,0 +1,22 @@ +#!/bin/dash + +## +# This creates function that will gather some system informations +# and propagate them as environment variables. +# + +. ./utils.sh +include_once system_information.sh +include_once interface_information.sh + +has_class() { + if [ 1 -ne $# ] + then + logger -p syslog.err 'has_class: no class given' + exit 1 + fi + + test "${CLASSES}" != "${CLASSES%${1}*}" +} + +# vim: set ts=4 sw=4: diff --git a/gnu_information.sh b/gnu_information.sh new file mode 100755 index 0000000..cc46989 --- /dev/null +++ b/gnu_information.sh @@ -0,0 +1,16 @@ +#!/bin/dash + +## +# This creates function that will gather some system informations +# and propagate them as environment variables. +# + +. ./utils.sh +include_once system_information.sh + +echo "foo ${NPROC}" +CPUS=$(${NPROC}) + +export CLASSES="${CLASSES}${CPUS}cpus " + +# vim: set ts=4 sw=4: diff --git a/run.sh b/run.sh index d27cb50..34e974f 100755 --- a/run.sh +++ b/run.sh @@ -10,9 +10,9 @@ # . ./utils.sh -include_once ./system_information.sh -include_once ../sysman/interface_information.sh -include_once /home/ghopp/sysman/network_tools.sh +include_once system_information.sh +include_once interface_information.sh +include_once network_tools.sh ## # report everysthing @@ -24,6 +24,7 @@ ${PRINTF} "%15s : %s\n" "VERSION" "${VERSION}" ${PRINTF} "%15s : %s\n" "PLATFORM" "${PLATFORM}" ${PRINTF} "%15s : %s\n" "DIST" "${DIST}" ${PRINTF} "%15s : %s\n" "HOSTNAME" "${HOSTNAME}" +${PRINTF} "%15s : %s\n" "CPUS" "${CPUS}" ${PRINTF} "%15s : %s\n" "# INTERFACES" "${NINTERFACES}" NO=1 @@ -44,3 +45,4 @@ echo $(mask2cidr 255.255.128.0) echo $(cidr2mask 17) eval echo \$\(cidr2mask $(mask2cidr 255.255.128.0)\) +# vim: set ts=4 sw=4: diff --git a/system_information.sh b/system_information.sh index 324bebc..5aa9555 100755 --- a/system_information.sh +++ b/system_information.sh @@ -125,4 +125,9 @@ get_dist_info() { [ -z "${DIST}" ] && get_dist_info +case "${OS}" in + GNU/*) + include_once gnu_information.sh;; +esac + # vim: set ts=4 sw=4: diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..377b947 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +logger -i -p syslog.err $0: blubber diff --git a/utils.sh b/utils.sh index 424712f..ad3efa5 100755 --- a/utils.sh +++ b/utils.sh @@ -12,7 +12,7 @@ then if [ 1 -ne $# ] then - logger -p syslog.err 'filename2sybol: missing filename' + ${LOGGER} -p syslog.err 'filename2sybol: missing filename' exit 1 fi @@ -29,11 +29,16 @@ then echo "${SYM}" } - canonify_name() { + ## + # create an absolute filename from a given relative one. + # This deals only with leading ./ and ../ it does not + # handle then when they are in the middle of the name. + # + abs_filename() { local FILE="${1}" local DIR="${PWD}" - # if FILE starts with a / its already canonified + # if FILE starts with a / its already absolute if [ "${FILE}" != ${FILE#/} ] then echo "${FILE}" @@ -56,19 +61,19 @@ then } include_once() { - local FILE="$(canonify_name "${1}")" + local FILE="$(abs_filename "${1}")" local SYM="$(filename2symbol "${FILE}")" if [ 1 -ne $# ] then - logger -p syslog.err 'include_once: missing filename' + ${LOGGER} -p syslog.err 'include_once: missing filename' exit 1 fi if eval [ -z \"\${SOURCED_${SYM}}\" ] then - . ${FILE} eval export SOURCED_${SYM}=\"\${FILE}\" + . ${FILE} fi } @@ -88,6 +93,7 @@ then [ -z "${TR}" ] && TR="$(${WHICH} tr)" [ -z "${PRINTF}" ] && PRINTF="$(${WHICH} printf)" [ -z "${LOGGER}" ] && LOGGER="$(${WHICH} logger)" + [ -z "${NPROC}" ] && NPROC="$(${WHICH} nproc)" [ -z "${IP}" ] && IP="$(${WHICH} ip)" [ -z "${IFCONFIG}" ] && IFCONFIG="$(${WHICH} ifconfig)"