如何让 bash 脚本在运行时打印到我的 putty 控制台。我以为我应该使用 Echo,但下面的脚本在执行时只给我一个空白终端,但仍按计划工作?
#!/bin/bash
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
if [ -e /var/log/s3extractLog.log ]
then
exec 1>>/var/log/s3extractLog.log 2>&1
else
touch /var/log/s3extractLog.log
exec 1>>/var/log/s3extractLog.log 2>&1
fi
date
###########################
# Self Explanatory printf #
###########################
if [[ ! $EUID == 0 ]]; then
echo "This script must be run as root."
exit 1
fi
function ISOCopy {
echo "Error: Failed to extract ISO from network share"
exit
}
function extractFunc {
# Extract the first installer ISO to local
if [ -e /home/s3user/isoFromExt/EXTRACTED_PACKAGES/$viaver/syngo.via-VB30A-Installer1-$viaver.iso ]
then
echo "VIA Installer1 Found"
#echo "Copying Installer-1 ISO from Share"
#rsync -av --progress /home/s3user/isoFromExt/EXTRACTED_PACKAGES/$viaver/syngo.via-VB30A-Installer1-$viaver.iso /home/s3user/extractedISOs/$viaver/
#echo "Copying ISO Completed!"
echo "Starting to EXTRACT the Installer-1 ISO"
sleep 3
cd /home/s3user/isoFromExt/EXTRACTED_PACKAGES/$viaver
7z x -y syngo.via-VB30A-Installer1-$viaver.iso -o/home/s3user/extractedISOs/$viaver/MBox/
echo "Installer-1 Extraction Complete"
else
echo "Required ISO File Not Found. Check The Network Archive For Validation"
exit 2
fi
# Extract the second installer ISO to local
if [ -e /home/s3user/isoFromExt/EXTRACTED_PACKAGES/$viaver/syngo.via-VB30A-Installer2-$viaver.iso ]
then
echo "VIA Installer2 Found"
pwd
echo "Starting to EXTRACT the Installer-2 ISO"
sleep 3
cd /home/s3user/isoFromExt/EXTRACTED_PACKAGES/$viaver
7z x -y syngo.via-VB30A-Installer2-$viaver.iso -o/home/s3user/extractedISOs/$viaver/MBox/
echo "Installer-2 Extraction Complete"
else
echo "Installer2 ISO Not Found. Check the Network Archive For Validation"
exit 2
fi
# Create a tag for the current VIA build
echo "Creating a tag for the current VB30A Build version"
cd /home/s3user/extractedISOs/$viaver/MBox/
touch $viaver.txt
echo "This file contains the version $viaver installer" >> $viaver.txt
echo "Tag Created"
cd /home/s3user/
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "| Copy the additional files to MBox for the FINAL VB30 Package |"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Starting RSYNC for MBox Creation"
sleep 3
rsync -av --progress /home/s3user/mboxPartS3/ /home/s3user/extractedISOs/$viaver/MBox/
echo "Copy to MBox Folder = Success"
echo "..."
echo "++++++++++++++++++++++++++++++++++++"
echo "| FINAL VB30A Mbox Installer Built |"
echo "++++++++++++++++++++++++++++++++++++"
}
exit 0
答案1
正如@Glenn Jackman 已经提到的,您将所有内容重定向exec
到日志文件。
如果你想登录并打印标准输出,您可以使用替代品。
exec 1> >(tee -a /var/log/s3extractLog.log) 2>&1
或者,由于您正在使用bash
exec &> >(tee -a var/log/s3extractLog.log)