I needed a quick way the change the Shared memory size on my ZM Machine, so i decided to build a script to do it for me, and ended up with the following, need someone to go it thru and tell me if iam all off or what, have tested it on my RedHat FC 3 and it seems to work.
Code: Select all
#!/bin/bash
#used for test purpose
#ZMDIR=`pwd`
#SYSCTL="$ZMDIR/etc/sysctl.conf"
# To change the Shared memory to half of the memory size of that u have installed in ur machine entehr the path for ur sysctl.conf
# below, on a RedHat Fedora Core 3 it is /etc/sysctl.conf
SYSCTL="/etc/sysctl.conf"
######################################################################################
# This line i found on the INet, not exactly sure what it does past the #
# ($1 / 2) * 1024, but my end result is half the size of the installed memory #
# into my variable SIZE, with that done i can now set my shared memory to that #
# size in sysctl.conf. #
SIZE=`dmesg | egrep 'Memory.*available' | perl -ne '/\/(\d+)/; $_ = ($1 / 2) * 1024; print $_ > 268435456 ? $_ : 268435456'`
######################################################################################
######################################################################################
# The 2 following variables wil bet set to the new shared mem limits #
KSHMAX="kernel.shmmax=$SIZE"
KSHMALL="kernel.shmall=$SIZE"
######################################################################################
######################################################################################
# Find the original shared memory lines in sysctl.conf file, #
# this i used in the find command #
KSHMAX_ORG=$(grep "kernel.shmmax=" $SYSCTL)
KSHMALL_ORG=$(grep "kernel.shmall=" $SYSCTL)
######################################################################################
# Display what we found
echo "KSHMAX is = $KSHMAX"
echo "KSHMALL is = $KSHMALL"
echo "KSHMAX_ORG is = $KSHMAX_ORG"
echo "KSHMALL_ORG is = $KSHMALL_ORG"
# Make a backup of the or sysctl.conf
cp $SYSCTL $SYSCTL.org
# Do the changes in the file and remove the blank lines in it
if [ "$KSHMAX_ORG" == "" ] && [ "$KSHMALL_ORG" == "" ]; then
echo "+++++++ ERROR : KSHMAX_ORG is empty and KSHMALL_ORG is empty"
perl -i -ne "print if /\S/" $SYSCTL
echo $KSHMAX >> $SYSCTL
echo $KSHMALL >> $SYSCTL
else
perl -i -ne "print if /\S/" $SYSCTL
perl -i -pe 's/'$KSHMAX_ORG'/'$KSHMAX'/g' $SYSCTL
perl -i -pe 's/'$KSHMALL_ORG'/'$KSHMALL'/g' $SYSCTL
fi
Any changes are welcome, and if u find it usefull then good.