我一直试图让bash脚本在终端和日志文件上输出不同的东西,但我不确定使用什么命令。Bash输出到不同的屏幕和日志文件
例如,
#!/bin/bash
freespace=$(df -h/| grep -E "/" | awk '{print $4}')
greentext="\033[32m"
bold="\033[1m"
normal="\033[0m"
logdate=$(date +"%Y%m%d")
logfile="$logdate"_report.log
exec > >(tee -i $logfile)
echo -e $bold"Quick system report for "$greentext"$HOSTNAME"$normal
printf "\tSystem type:\t%s\n" $MACHTYPE
printf "\tBash Version:\t%s\n" $BASH_VERSION
printf "\tFree Space:\t%s\n" $freespace
printf "\tFiles in dir:\t%s\n" $(ls | wc -l)
printf "\tGenerated on:\t%s\n" $(date +"%m/%d/%y") # US date format
echo -e $greentext"A summary of this info has been saved to $logfile"$normal
我想省略在日志文件中的最后一个输出(回声“A摘要...”),而在终端中显示它。有没有这样的命令?如果可以提供一个通用的解决方案而不是特定的解决方案,这将是非常好的,因为我想将其应用于其他脚本。 EDIT 1(之后施加> & 6)
:
Files in dir: 7
A summary of this info has been saved to 20160915_report.log
Generated on: 09/15/16
欢迎的网站!不要忘了查看[tour](https://stackoverflow.com/tour)了解更多特定于站点的详细信息(以及徽章:))。 – cxw