From b2a786d07ac0c8e3ae7cb08ef5714b22eaae9f1b Mon Sep 17 00:00:00 2001 From: Jared Still Date: Thu, 4 Aug 2016 08:28:05 -0700 Subject: [PATCH] Updated the regex for soft and hard memlock - get only the last entry in the event of duplicates. - recognize 'infinity' and '-1' in addition to 'unlimited' as per limits.conf man page --- limits-test.conf | 22 ++++++++++++++++++++ mem_verify.sh | 15 ++++++++------ regex-test.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 limits-test.conf create mode 100755 regex-test.sh diff --git a/limits-test.conf b/limits-test.conf new file mode 100644 index 0000000..eb7bb7b --- /dev/null +++ b/limits-test.conf @@ -0,0 +1,22 @@ + +oracle soft nproc 2047 +oracle hard nproc 16384 +oracle soft nofile 1024 +oracle hard nofile 65536 + +oracle soft memlock 2048 +oracle soft memlock 1024 +#oracle soft memlock -1 +#oracle soft memlock infinity +#oracle soft memlock unlimited +oracle soft memlock bogus + +oracle hard memlock 2048 +oracle hard memlock 1024 +#oracle hard memlock -1 +#oracle hard memlock infinity +oracle hard memlock unlimited +oracle hard memlock bogus + + + diff --git a/mem_verify.sh b/mem_verify.sh index 751886b..de283cc 100755 --- a/mem_verify.sh +++ b/mem_verify.sh @@ -218,17 +218,20 @@ SHMALL=$(cat /proc/sys/kernel/shmall) # if 'unlimited' then set to value of total memory LIMITS_FILE='/etc/security/limits.conf' -SOFT_MEMLOCK=$( grep -E '^oracle.*soft.*memlock.*unlimited|^oracle.*soft.*memlock.*[0-9]++' $LIMITS_FILE | awk '{ print $4 }') +# from the limits.conf man page +# All items support the values -1, unlimited or infinity indicating no limit, except for priority and nice. + +SOFT_MEMLOCK=$( grep -E '^oracle.*soft.*memlock.*(unlimited|infinity|-1)|^oracle.*soft.*memlock.*[0-9]++' $LIMITS_FILE | tail -1 | awk '{ print $4 }') if [[ -z $SOFT_MEMLOCK ]]; then - SOFT_MEMLOCK=$( grep -E '^\*.*soft.*memlock.*unlimited|^\*.*soft.*memlock.*[0-9]+' $LIMITS_FILE | awk '{ print $4 }') + SOFT_MEMLOCK=$( grep -E '^\*.*soft.*memlock.*(unlimited|infinity|-1)|^\*.*soft.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }') fi -[[ $SOFT_MEMLOCK == 'unlimited' ]] && SOFT_MEMLOCK=$TOTALMEM +[[ $(echo $SOFT_MEMLOCK | grep -E 'unlimited|infinity|-1') ]] && SOFT_MEMLOCK=$TOTALMEM -HARD_MEMLOCK=$( grep -E '^oracle.*hard.*memlock.*unlimited|^oracle.*hard.*memlock.*[0-9]+' $LIMITS_FILE | awk '{ print $4 }') +HARD_MEMLOCK=$( grep -E '^oracle.*hard.*memlock.*(unlimited|infinity|-1)|^oracle.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }') if [[ -z $HARD_MEMLOCK ]]; then - HARD_MEMLOCK=$( grep -E '^\*.*hard.*memlock.*unlimited|^\*.*hard.*memlock.*[0-9]+' $LIMITS_FILE | awk '{ print $4 }') + HARD_MEMLOCK=$( grep -E '^\*.*hard.*memlock.*(unlimited|infinity|-1)|^\*.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }') fi -[[ $HARD_MEMLOCK == 'unlimited' ]] && HARD_MEMLOCK=$TOTALMEM +[[ $(echo $HARD_MEMLOCK | grep -E '(unlimited|infinity|-1)|infinity|-1') ]] && HARD_MEMLOCK=$TOTALMEM [[ -z $SOFT_MEMLOCK ]] && SOFT_MEMLOCK=0 [[ -z $HARD_MEMLOCK ]] && HARD_MEMLOCK=0 diff --git a/regex-test.sh b/regex-test.sh new file mode 100755 index 0000000..895176e --- /dev/null +++ b/regex-test.sh @@ -0,0 +1,53 @@ +#!/usr/bin/bash + +# test regex for pulling memlock from /etc/security/limits.conf + +# duplicate entries may appear in the file +# the following are duplicates for 'oracle soft memlock' +# the second one of 1078768 will be the one used by the system +# +# oracle soft memlock 5078768 +# oracle soft memlock 1078768 + +# Test Variables +TOTALMEM=33554432 +(( TOTALMEM_BYTES = TOTALMEM * 1024 )) +LIMITS_FILE=limits-test.conf +####################################### + +# from the limits.conf man page +# All items support the values -1, unlimited or infinity indicating no limit, except for priority and nice. + +SOFT_MEMLOCK=$( grep -E '^oracle.*soft.*memlock.*(unlimited|infinity|-1)|^oracle.*soft.*memlock.*[0-9]++' $LIMITS_FILE | tail -1 | awk '{ print $4 }') +if [[ -z $SOFT_MEMLOCK ]]; then + SOFT_MEMLOCK=$( grep -E '^\*.*soft.*memlock.*(unlimited|infinity|-1)|^\*.*soft.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }') +fi +[[ $(echo $SOFT_MEMLOCK | grep -E 'unlimited|infinity|-1') ]] && SOFT_MEMLOCK=$TOTALMEM + +HARD_MEMLOCK=$( grep -E '^oracle.*hard.*memlock.*(unlimited|infinity|-1)|^oracle.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }') +if [[ -z $HARD_MEMLOCK ]]; then + HARD_MEMLOCK=$( grep -E '^\*.*hard.*memlock.*(unlimited|infinity|-1)|^\*.*hard.*memlock.*[0-9]+' $LIMITS_FILE | tail -1 | awk '{ print $4 }') +fi +[[ $(echo $HARD_MEMLOCK | grep -E '(unlimited|infinity|-1)|infinity|-1') ]] && HARD_MEMLOCK=$TOTALMEM + +[[ -z $SOFT_MEMLOCK ]] && SOFT_MEMLOCK=0 +[[ -z $HARD_MEMLOCK ]] && HARD_MEMLOCK=0 + +(( SOFT_MEMLOCK_BYTES = SOFT_MEMLOCK * 1024 )) +(( HARD_MEMLOCK_BYTES = HARD_MEMLOCK * 1024 )) + + +cat <