
FILE_CENT="/etc/nsswitch.conf"
if [[ $OS = 'Linux' ]]; then
if [[ -e $FILE_CENT ]]; then
logInfo "nsswitch.conf found in $OS, Proceeding further..."
while read -r LINE
do
if [[ `echo $LINE | sed '/^passwd/'` ]]; then
myarrlin=($LINE)
logInfo "ARRAY VALUES : ${myarrlin[0]},${myarrlin[1]},${myarrlin[2]}"
if [[ `echo ${myarrlin[1]} | egrep -s "centrify$|^centrifydc$"` || `echo ${myarrlin[2]} | egrep -s "centrify$|^centrifydc$"` ]]; then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi
fi
done < $FILE_CENT
else
logInfo "nsswitch.conf does not exist in $OS, cannot fetch CENTRIFY information!"
fi
fi
ここではパターンマッチングのためにsedとegrepを使用していますが、どちらも正しい結果を提供しません。
また、egrepで正規表現を使用できるかどうかはわかりません。 KSHでパターンマッチング作業をしています。
答え1
ロジックを簡素化し、「centrify」文字列が/etc/nsswitch.confの「passwd:」行にあるかどうかを尋ねます。ループwhile
全体を次に置き換えます。
if grep -q '^passwd:.*centrify' /etc/nsswitch.conf
then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi