Skip to main content
deleted 40 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 237

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 (or at least the part I need help with) 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?

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 (or at least the part I need help with) 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?

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?

Source Link
Patrick
  • 214
  • 1
  • 11

Writing user input to file using tee

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 (or at least the part I need help with) 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?