Hello all,
working on Solaris 10 in ksh.
Basicly, in my function, i'm trying to test that all my unix cmd's are true (exit status 0) else you flag the rcControlRule to 1 without going into spagetti mode code testing every $? in a if statement.
The mdb is probably a little tricky cause it will give something like this:
# echo noexec_user_stack/D | mdb -k
noexec_user_stack:
noexec_user_stack: 1
And i'm looking for something like this:
# echo noexec_user_stack/D | mdb -k
noexec_user_stack:
noexec_user_stack: 0
Bottom line i just want to know how you guys evaluate unix command without testing $? everytime... there must be a simpler way. A best practice somewhere that i miss.
Bellow code doesn't work but basicly explain what i'm trying to do.
CONFIG_FILE="/etc/system"
STACK=$(grep -q "^set noexec_user_stack=1" ${CONFIG_FILE})
STACK_LOG=$(grep -q "^set noexec_user_stack_log=1" ${CONFIG_FILE})
MDB=$(echo "noexec_user_stack/D" | mdb -k)
check_config () {
if [[ ${STACK} -a ${STACK_LOG} -a ${MDB} ]]; then
rcControlRule=0
else
rcControlRule=1
fi
return ${rcControlRule}
}
Maybe i should use something like:
set -A services "grep -q \"^set noexec_user_stack=1\" ${CONFIG_FILE}" "grep -q \"^set noexec_user_stack_log=1\" ${CONFIG_FILE}" "echo \"noexec_user_stack/D\" | mdb -k"
check_service () {
i=0
while [[ $i -lt "${#services[@]}" ]] && [[ rcControlRule -ne 1 ]]; do
if ! "${services[$i]}" > /dev/null 2>&1; then
rcControlRule=1
else
rcControlRule=0
fi
(( i+=1 ))
done
return ${rcControlRule}
}
Thanks.
Eric