?
Solved

Bash Logging

Posted on 2008-11-03
7
Medium Priority
?
2,870 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:Sam Cohen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 600 total points
ID: 22867352
use the command script at the begining of the script

script filename
stuff here
exit

for more info, please see

man script
0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 22867440
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.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22867492
if the script requires user input, how do you intend to run it as a background script?
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 8

Author Comment

by:Sam Cohen
ID: 22867534
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.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 600 total points
ID: 22869571
It's trickier to do it from the script.

So long as you don't need to capture the user input, just do

./webappinstaller.sh | tee -a /some/log

If you don't want to type that at the command line, then just create a wrapper script to call the above line.
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 22916635
or you may redirect the script output to a log file. Then redirect the log to /dev/stdout
0
 
LVL 6

Assisted Solution

by:peter991
peter991 earned 300 total points
ID: 23537005
You could start a second shell/window and run "tail -f your_logfile"

You could also turn on debugmode by using

#!/usr/bin/bash -xv

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question