Hi there,
I'm stumped and thinking that my logic is way off. I'd appreciate another set
of eyes looking over my shoulder to help my catch my logic error.
Here's my dilemma, I am setting several variables, I have several variable
arrays, one variable array consists of names of previously set variables, my
script attempts in a "while" loop to check each variable in the variable array
and set it if necessary.
I'm using conditional parameter substitution to set my variables inside my
variable arrays. Is this just not possible and I'm approaching this wrong?
Here's my example script. And if there's a better way of doing this, I'm always
open to better practices.
Thanks for your time and effort,
Andi
------------------------------------------------------------------
#!/usr/bin/ksh
#set -x
#-------------------chk_kernel.ksh--------------------------------
# This script will be part of an app. installation script that
# checks the kernel parameters, warns the installer if a reboot
# would be necessary, and eventually copy the /etc/system file
# and add the changes in.
#-----------------------------------------------------------------
#--VARIABLES
#----------------
# System settings
#----------------
CHG_SYSTEM_SEMMAP="false"
CHG_SYSTEM_SEMMNI="false"
SYSTEM_SEMMAP=$(grep seminfo_semmap /etc/system | awk -F= '{print $2}')
SYSTEM_SEMMNI=$(grep seminfo_semmni /etc/system | awk -F= '{print $2}')
#--VARIABLE ARRAYS
#-------------------------
# Kernel Module Parameters
#-------------------------
set -A CHGMODPARAM_NAMES -- "CHG_SYSTEM_SEMMAP" "CHG_SYSTEM_SEMMNI"
set -A CHGMODPARAM_VARS -- "$CHG_SYSTEM_SEMMAP" "$CHG_SYSTEM_SEMMAP"
set -A MODPARAM_NAMES -- "SYSTEM_SEMMAP" "SYSTEM_SEMMNI"
set -A MODPARAM_VALUES -- "50" "100"
set -A MODPARAM_VARS -- "$SYSTEM_SEMMAP" "$SYSTEM_SEMMNI"
set -A MODPARAMS -- "semsys:seminfo_semmap" "semsys:seminfo_semmni"
#--FUNCTIONS
kernel_module_parameters()
{
(( i = 0 ))
while (( i < n ))
do
#--------------------------------------------------------------------------
#
# Checking for variable and size of kernel parameter, adjusting if needed.
#
#--------------------------------------------------------------------------
CHK_KERN_PARAM=${MODPARAM_VARS[$i]:-"${MODPARAM_VALUES[$i]}"}
case $? in
0) # The variable is set and not null, need to check variable.
[ "${MODPARAM_VARS[$i]}" -ge "${MODPARAM_VALUES[$i]}" ]
;;
case $? in
0) # The variable is set correctly to MODPARAM_VALUES or greater.
print "Kernel parameter: ${MODPARAMS[$i]} is >= \
${MODPARAM_VALUES[$i]}."
;;
1) # The variable is less than MODPARAM_VALUES, change variable
${CHGMODPARAM_NAMES[$i]:+"${MODPARAM_VALUES[$i]}"} #TROUBLE AREA
print ${CHGMODPARAM_NAMES[$i]} # Temp to see if the var. changed
# CHG_${MODPARAM_NAMES[$i]}="${MODPARAM_VALUES[$i]}" #Test idea
print ${CHGMODPARAM_VARS[$i]} # Temp to see what the var really is
print "Kernel parameter: ${MODPARAMS[$i]} is not >= \
${MODPARAM_VALUES[$i]}, a reboot would be necessary."
;;
esac
1) # The variable is either null or unset, need to set
${CHGMODPARAM_NAMES[$i]:="${MODPARAM_VALUES[$i]}"} #TROUBLE AREA
print "Kernel parameter: ${MODPARAMS[$i]} is not >= \
${MODPARAM_VALUES[$i]}, a reboot would be necessary."
;;
esac
((i+=1))
done
#--MAINQuote:}
kernel_module_parameters
--------------------------------------------------------------------------