【发布时间】:2020-09-15 11:16:18
【问题描述】:
我在成员“reto”的评论中遇到了以下命令,这将满足我的大部分需求。不幸的是,我刚加入时无法发表评论。
他们做了我想做的大部分事情,但我也希望在我的脚本中的某些时间将标准输出重定向到屏幕;如果 if 语句失败,则要求用户输入用户名和密码时。然后在用户交互完成后将标准输出恢复为日志记录。
任何帮助都会很棒。 更新
#this works for me
LOGFILE=./ClamAV_install_script.log
exec 3>&1 >$LOGFILE 2> >(tee -a $LOGFILE >&2)
# Everything below will go to the file 'ClamAV_install.log':
date
#all these go to screen
{
tail -40 ./ClamAV_install_script.log
#To give option to scan full system
printf "\n\n\nDo you wise to scan the full file system / ? \n"
read -p 'Type Y to scan: ' Conformation
printf "\nYou have entered: $Conformation\n"
} >&3
#!/bin/bash
set -e
outfile=logfile
exec > >(cat >> $outfile)
exec 2> >(tee -a $outfile >&2)
#STDOUT 和 STDERR 将被写入 $outfile,控制台上只会看到 STDERR
【问题讨论】:
标签: bash logging scripting stdout stderr