I am facing the following issue and cannot think of a way to iterate multiple arrays from within one parent for loop.
For example, the current code is this:
main_array=("STRING1" "STRING2" "STRING3")
array1=(1 2 3)
array2=(4 5 6)
array3=(7 8 9)
I need the code that will print following output:
STRING1
1
2
3
STRING2
4
5
6
STRING3
7
8
9
In essence, I need for loop that iterates through main_array (see above), then inside that loop another for loop that iterates array1. Once finished, parent for loop prints STRING2, then iterates throgh array2, and so on.
EDIT:
Here is my (truncated) attempt:
packages=("NETWORK" "FILE_SYSTEM")
NETWORK=(DBMS_LDAP UTL_INADDR UTL_TCP UTL_MAIL UTL_SMTP UTL_DBWS UTL_ORAMTS UTL_HTTP HTTPURITYPE)
FILE_SYSTEM=(DBMS_ADVISOR DBMS_LOB UTL_FILE)
for package in "${packages[@]}"; do
echo "Ensure 'EXECUTE' is revoked from 'PUBLIC' on $package Packages"
for i in ${NETWORK[@]}; do
/bin/echo -e "Current setting for $i:"
RESULT=$(grep -Ei "^PUBLIC;.*$i;.*EXECUTE.*" file.txt)
if [[ -z "$RESULT" ]]; then
/bin/echo -e "Setting for $i is properly configured.\n"
else
/bin/echo -e "[!] This is not recommended setting! EXECUTE privilege should not be enabled for $i\n"
fi
done
done
OUTPUT:
======================================================================
Ensure 'EXECUTE' is revoked from 'PUBLIC' on NETWORK Packages
======================================================================
[+] Current setting for DBMS_LDAP:
PUBLIC;SYS;DBMS_LDAP;SYS;EXECUTE;NO;NO
[!] This is not recommended setting! EXECUTE privilege should not be enabled for DBMS_LDAP
[+] Current setting for UTL_INADDR:
PUBLIC;SYS;UTL_INADDR;SYS;EXECUTE;NO;NO
[!] This is not recommended setting! EXECUTE privilege should not be enabled for UTL_INADDR
***TRUNCATED REPETITIVE - REST OF NETWORK ARRAY IS PRINTED HERE***
***CHILD FOR LOOP IS OVER, MAIN ARRAY STARTS***
======================================================================
Ensure 'EXECUTE' is revoked from 'PUBLIC' on FILE SYSTEM Packages
======================================================================
[+] Current setting for DBMS_LDAP:
**##### Issue here, needs to iterate values from FILESYSTEM array**
PUBLIC;SYS;DBMS_LDAP;SYS;EXECUTE;NO;NO
[!] This is not recommended setting! EXECUTE privilege should not be enabled for DBMS_LDAP
Thank you!