Sam Cohen
asked on
Bash Logging
I have a multi function bash script that needs to have good logging. I am currently using the following method, however is not exactly ideal.
function name() {
stuff here | tee -a ${LOG}
}
This works, however I would like to find a way to use one function to log all output from the script. I have also tried the following method which does not seem to work very well as it causes script errors.
function name() {
stuff here
} | tee -a ${LOG}
The biggest thing with the logging function is that I must be able to see verbose information on the screen while it is also being captured to the log. I was able to get the following to do pretty decent logging, however it does not display anything on the screen.
function name() {
stuff here
} >> ${LOG}
Any help would be greatly appreciated. Thanks again in advance.
function name() {
stuff here | tee -a ${LOG}
}
This works, however I would like to find a way to use one function to log all output from the script. I have also tried the following method which does not seem to work very well as it causes script errors.
function name() {
stuff here
} | tee -a ${LOG}
The biggest thing with the logging function is that I must be able to see verbose information on the screen while it is also being captured to the log. I was able to get the following to do pretty decent logging, however it does not display anything on the screen.
function name() {
stuff here
} >> ${LOG}
Any help would be greatly appreciated. Thanks again in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if the script requires user input, how do you intend to run it as a background script?
ASKER
I do not want it to run in the background. But when I use your suggestion (script) that is what happens. If I remove it the script works fine.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or you may redirect the script output to a log file. Then redirect the log to /dev/stdout
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
[root@centbox trunk]# ./webappinstaller.sh
Script started, file is scriptlog
[root@centbox trunk]#
Unfortunately the only problem is that this script requires user input and has a full blown menu. If the script just runs in the background it cannot be used.