Sorry for possible spam, I'm finishing RHEL Security Hardening/Auditing script, where I want an overall result in the end. For example,
# PermitEmptyPasswords
grep -E '^\s*PermitEmptyPasswords\s+no\s*' /etc/ssh/sshd_config &> /dev/null
if [ $? = 0 ];
then echo "[ OK ] PermitEmptyPasswords is properly configured";
else echo "[ ERROR ] PermitEmptyPasswords is not properly configured";
fi
Now, my idea for overall result (Safe/Not safe) is to make sum of all these if $? cases, if all cases give sum of 0, it will echo "This system is properly configured by hardening policy", else echo "This system has errors" + reprint all errors where $? is > 0.
How to get this work? I'm new at scripting, so any help will be appreciable. Thanks in advance.
$?is generated for every shell command run and bash does not store the history of exit codes of all the previous commands, just the last command's value is known in$?. Explain your requirement more, I am sure there is a better way to do what you are trying to achieve herefoo; (( retval |= $? ))ORs the bits of$?from commandfooin with what you already have in the variableretval.