I have quite a big script written. The script works well, the issue I have is with redirect. I have done the following block for redirect to a log file:
log_location=/home/admin exec > >(tee -i $log_location/health-check.log) exec 2>&1 echo -e "Output will be saved at $log_location/health-check.log\n"
The script has the following for colors:
G="\033[32m" N="\033[0m" R="\033[31m" Y="\033[33m"
The console output of this prints in the colored format for required characters. However, when I less the .log file, it ends up as a binary file and upon viewing I see something like this:
ESC[33mGSANESC[0m Service Status is |ESC[32mUPESC[0m ESC[33mMCSESC[0m Service Status is |ESC[32mUPESC[0m ESC[33mTomcatESC[0m Service Status is |ESC[32mUPESC[0m ESC[33mSchedulerESC[0m Service Status is |ESC[31mDOWNESC[0m ESC[33mMaintenanceESC[0m Service Status is |ESC[31mSUSPENDEDESC[0m
I don't mind having non colored output in log files. Is there a way I can get this done?