Creating a script requiring a pause for user input

Hi I'm trying to create a basic script that pauses for user input to verify a file name before generating the output.

I have numerous SSL certificate files which I am trying to determine the expiry date so what I'm trying to do is write a script so that is pauses to request the name of the .pem file and then checks that the file within the directory then runs the command against that file to output the Certificate info. This is what I'm looking for.

#!/bin/bash
#
# This Script Will Check the Validity Of an SSL CERT

echo  "Please Enter Name Of .pem File To Be Checked [ENTER]:"
echo
echo
          [Checks That File Exists.... 

      if exists then 

  openssl x509 -text -in {name of .pem file user has input}

     if file doesn't exist then

 print .pem file doesn't exist 

exit

Any help on this please

try to use this

if [ -f $file ]; then
echo "exists"
else
echo "not existing"
fi

Thanks

But I need help on how to script it all so that it will prompt me and take my input to run the command

openssl x509 -text -in

if the input file doesn't exist then I need it to advise 'File Doesn't Exist' and exit

You can prompt the user with echo or printf, and read text via read VARNAME

echo -n "Please Enter Name Of .pem File To Be Checked [ENTER]: "
read file

if [ -f "$file" ]; then
  openssl x509 -text -in "$file"
else
  echo "File Doesn't Exist: $file"
  exit # from shell script
fi
1 Like

:b:Thanks Hanson44

This works exactly as I needed ...
Now all I need is to be able to continue to check others without exiting the script every time, so after checking the first one I need a question?

Do you wish to check another [y/n]
If the answer is 'y'
Then Go Back to Beginning 
Else exit

Can you assist here also ?

Do "man bash" on the command line and inside the manpage search for the "select" builtin command...

Here is one good way to do it:

while [ 1 -eq 1 ]; do
  echo -n "Please Enter Name Of .pem File To Be Checked [ENTER]: "
  read file

  if [ -f "$file" ]; then
    openssl x509 -text -in "$file"
  else
    echo "File Doesn't Exist: $file"
  fi

  echo -n "Do you wish to check another [y/n]: "
  read yn
  if [ "$yn" != "y" ]; then
    exit # from shell script
  fi
done
1 Like

while : ; do
or use select as previously suggested.

Why not

$ while read -p "Enter file name; <ctrl>D to end" file
     do  [ -f "$file" ] && openssl x509 -text -in "$file"  || echo "File Doesn't Exist: $file" 
     done