0

I have a script which guides users through the installation of my software and I want to write a log file in case something bad happens and the user needs support.

The script looks like this:

while true; do
  echo "This script will help you with the installation. Do you wish to proceed?"
  echo "(1) Yes"
  echo "(2) No"
  read proceed
  case $proceed in
    1 ) break;;
    * ) echo "Aborting."; exit 8;;
  esac
done
unset proceed

I then run it by using ./install.ksh | tee /var/log/myinstall.log and everything works just fine, but the user input to the question is not logged. When I add echo $proceed after the read command, it is written to the log but displayed twice, like that:

This script will help you with the installation. Do you wish to proceed?
(1) Yes
(2) No
1 #this is the input which is not written to the log
1 # this is the echo which is written to the log

My question is now how I could either suppress the output of the read command or how I could write the echo only to the file but not to STDOUT?

  • Why not just echo "You chose $proceed, continuing"? – Mikel Mar 13 '18 at 14:56
1

You should use script instead, it’s designed for exactly this purpose:

script /var/log/myinstall.log -c ./install.ksh

It will log the input to read as well as any output.

  • Now another problem occurred. I need to support AIX and the AIX korn shell does not support -c, only -a for append and -q for qiet. Any ideas how to run it without -c? – Patrick Mar 15 '18 at 10:34
  • I was going to suggest asking a new question but I see you’ve just done that ;-). – Stephen Kitt Mar 15 '18 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.