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