Matty9191 / ssl-cert-check

Send notifications when SSL certificates are about to expire.
GNU General Public License v2.0
719 stars 285 forks source link

-f does not work with process substitution #123

Open codigoergosum opened 1 year ago

codigoergosum commented 1 year ago

$ 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.

pillilz commented 1 year ago

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.