I have script that checks the availability of package on my server, it iterate through array and should return [INSTALLED]
if it is. Below script is modified to the basic to give you understanding what'd it do.
#!/bin/bash
declare -a prog=("mysql-server" "apache2" "php" "ufw")
declare -a snap=("beer")
for f in "${!prog[@]}"; do
for connect in "${snap[@]}"; do
ssh jan@"$connect" /bin/bash <<- EOF
if [ \$(dpkg --get-selections | grep -E "(^|\s)${prog[$f]}(\$|\s)" | wc -l) -gt 0 ]; then
prog[$f]="${prog[$f]} [INSTALLED]" # The program is already installed
echo "\${prog[@]}"
else
echo "False"
fi
EOF
done
done
This should return the package name and [INSTALLED]
suffix if it is installed, otherwise it will only return the package name.
I expect the output to be:
mysql-server [INSTALLED]
apache2 [INSTALLED]
php [INSTALLED]
ufw
Turns out the output was:
mysql-server [INSTALLED]
apache2 [INSTALLED]
php [INSTALLED]
False
ufw
package is not installed on the server, I expect it to return ufw
instead Not installed
— if I remove the else clause altogether, ufw
would not be appear on the output at all.