Bash Script Will Not Print out to Console

Bash Script Will Not Print out to Console

How do I get a bash script to print out to my putty console when run. I thought I am supposed to use Echo but My script below only gives me a blank terminal when executed yet still works as planned?

#!/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

1 Answer

As @Glenn Jackman already mentioned, you redirect everything with exec to the logfile.

If you want to log and print it on stdout, you could use a substitution.

exec 1> >(tee -a /var/log/s3extractLog.log) 2>&1

Or, since you are using bash

exec &> >(tee -a var/log/s3extractLog.log)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.