Link to home
Start Free TrialLog in
Avatar of Sam Cohen
Sam CohenFlag for United States of America

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.
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sam Cohen

ASKER

Ok, I added this to the start of the script, which is generating a timestamp, however thats all it does. Here is how it executes:

[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.
if the script requires user input, how do you intend to run it as a background script?
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or you may redirect the script output to a log file. Then redirect the log to /dev/stdout
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial