tee を使用してユーザー入力をファイルに書き込みます。

tee を使用してユーザー入力をファイルに書き込みます。

ソフトウェアのインストールプロセスをユーザーに案内するスクリプトがありますが、問題が発生してユーザーにサポートが必要な場合に備えてログファイルを作成したいと思います。

スクリプトは次のとおりです。

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

./install.ksh | tee /var/log/myinstall.logその後、次のように実行しました。コマンドecho $proceedの後に追加するとreadログに記録されますが、次のように2回表示されます。

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

今私の質問は、コマンドの出力をどのように抑制できるかread、またはどのようにechoSTDOUT以外のファイルに書き込むかです。

ベストアンサー1

使用する必要がありますscript逆に、これはまさに次の目的のために設計されています。

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

read入力と出力の両方を記録します。

おすすめ記事