ssl-cert-check
ssl-cert-check copied to clipboard
-f does not work with process substitution
$ bash -x ssl-cert-check -f <(echo -e 'example.com 443')
fails because /dev/fd/63 does not satisfy the test:
elif [ -f "${SERVERFILE}" ]; then
which looks for an extant regular file. However, a regular file should not be required, just a readable one. In bash, I'd suggest the -r test instead--I can't speak to other shells.
Similarly the following does not work due to [ -f "${SERVERFILE}" ]
:
$ echo example.com 443 | ssl-cert-check -f /dev/stdin
Another disadvantage is the race condition between the test and grep actually opening the file. Not a big issue, but not ideal either. I propose to change the code like this:
elif [ -n "${SERVERFILE}" ]; then
print_heading
grep -E -v '(^#|^$)' "${SERVERFILE}" | while read HOST PORT
do
if [ "$PORT" = "FILE" ]; then
check_file_status "${HOST}" "FILE" "${HOST}"
else
check_server_status "${HOST}" "${PORT}"
fi
done
if [ ${PIPESTATUS[0]} != 0 ]
then
echo "Error opening ${SERVERFILE}"
else
print_summary
fi
Happy to raise a pull request if desired.