Search code examples
linuxbashterminalopenssl

set a timeout and error message on my script


I have a script that im trying to create an error message and timeout for if the openssl takes to long. Here is the script. Can anyone help me? I'm a little lost.


FILENAME=$1
while read -r ip; do
 echo "${ip}"
 echo -n | openssl s_client -connect "${ip}:443" -showcerts 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -noout -dates

done < <(cut -d "," -f2 $FILENAME | tail -n +2)

Solution

  • You could use timeout from gnu core utils package(manual)
    Maybe do something like:

    while read -r ip; do
     timeout [timeout duration] [your ssl command]
    
     if [ $? -eq 124 ]; then
      echo FAIL
     else
      echo OK
     fi
    done