Sponsored Content
Top Forums Shell Programming and Scripting Dual output (stdout and file) Post 302111938 by ennstate on Friday 23rd of March 2007 12:35:17 PM
Old 03-23-2007
Using Log Function

Code:
#!/bin/ksh

LOG_FILE=/tmp/${0##*/}.log

LogMsg() {

 #Redirecting the Output just to the Log file.
 #print "$@:$(date +%d/%m/%y:%H:%M:%S)"  >> $LOG_FILE

 #Redirection to stdout and file.
 print "$@:$(date +%d/%m/%y:%H:%M:%S)"  | tee -a $LOG_FILE
}

CallB() {
 LogMsg "Entering CallB routine"
}

Main() {
 LogMsg "Entering the function"
 CallB
}

#Call the Main Function here.
 Main

Just in case in future after having tested code you may have to remove logging,using the above approach you have just haveto change the LOG_FILE=/dev/null or LogMsg function.


Pls comment of the above approach.

Thanks
Nagarajan Ganesan.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

sending syslog output to stderr or stdout

Is there a way to send the syslog output for a given facility to stderr or stdout? I do not want to use the "tail" command to achieve this, I would like it to go directly to stderr. Thanks in advance (1 Reply)
Discussion started by: dmirza
1 Replies

2. Shell Programming and Scripting

Script Output Woes (stdout?)

Hey everyone. I have been trying a few filtering scripts with both SED and PERL. So far I have both of these versions working to reformat the incoming text stream (from stdin) into the corrent format (it looks good in the terminal), but I don't think that I am doing it right because the... (2 Replies)
Discussion started by: c0nn0r
2 Replies

3. Shell Programming and Scripting

getting stderr & stdout output lively modified

This is about getting all output to stderr and stdout localized. Nothing to do with redirecting output to a file (there already are some interesting threads about that issue on this forum). What I intend to do is capturing all lines of text sent to the screen, compare them with an array of... (2 Replies)
Discussion started by: teo ramirez
2 Replies

4. Shell Programming and Scripting

let curl output to stdout AND save to a file

hello hackers. i have a curl process running as cgi directly pushing stdout to the client. but i want to additionally save that stream to a file at the same time. any directions madly welcome. thanks in advance (3 Replies)
Discussion started by: scarfake
3 Replies

5. Shell Programming and Scripting

Creating an Array in KSH from output (stdout)

Using Cygwin PDksh - But also have tested it on Linux with same results ---- I have a script that invokes a program/script and returns a string of data (1234 "12 34 56" 6789) and using "set -A" inserting it into an array. script code snipit >> get_array=$(php... (2 Replies)
Discussion started by: carlos25
2 Replies

6. Shell Programming and Scripting

Redirecting part of output to stdout

Hi, I am trying to execute a command like this: find ./ -name "*.gz" -exec sh -c 'zcat {} | awk -f parse.awk' \; >> output If I want to print the filename, i generally use the -print argument to the find command but when I am redirecting the output to a file, how can I print just the... (2 Replies)
Discussion started by: Legend986
2 Replies

7. Programming

Print C file output both in stdout and file

Hello! I want to post a question. does anybody know how to print the output of a C program both in stdout and a file?? thanx (8 Replies)
Discussion started by: nicos
8 Replies

8. Shell Programming and Scripting

File descriptors, redirecting output, and stdout

Hello all. I've been lurking here for a year or two and finally decided to post. I need some assistance with file descriptors, stdout, and redirecting output. I've searched through a number of very helpful threads here (unfortunately I can't link to any of them yet due to my low post count...),... (2 Replies)
Discussion started by: Michael_K
2 Replies

9. Shell Programming and Scripting

Redirecting stdout output to whiptail menu box

As a result of whiptail menu option I am getting a data from a file. Naturally it is output to terminal as stdour. I like to redirect the output back to the menu. It can be done with single input of line of text , see attached. I just cannot see where or how the sample... (0 Replies)
Discussion started by: annacreek
0 Replies

10. UNIX for Beginners Questions & Answers

Output of until to file versus stdout

Why does this until false; do history | head -5; done result in a stdout infinite loop, yet until false; do history | head -5 > hist5; done only writes it once to file hist5? Furthermore, I can hear the hard drive working on the 2nd command until I end the process, but the history | head -5 is... (1 Reply)
Discussion started by: Xubuntu56
1 Replies
SCRIPT(1)							   User Commands							 SCRIPT(1)

NAME
script - make typescript of terminal session SYNOPSIS
script [options] [file] DESCRIPTION
script makes a typescript of everything displayed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves the dialogue in this file. If no filename is given, the dialogue is saved in the file type- script. OPTIONS
-a, --append Append the output to file or to typescript, retaining the prior contents. -c, --command command Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -e, --return Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n. -f, --flush Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can supervise real-time what is being done using `cat foo'. --force Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic link. -q, --quiet Be quiet (do not write start and done messages to standard output). -t[file], --timing[=file] Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. -V, --version Display version information and exit. -h, --help Display help text and exit. NOTES
The script ends when the forked shell exits (a control-D for the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. It is not recommended to run script in non-interactive shells. The inner shell of script is always interactive, and this could lead to unexpected results. If you use script in the shell initialization file, you have to avoid entering an infinite loop. You can use for example the .profile file, which is read by login shells only: if test -t 0 ; then script exit fi You should also avoid use of script in command pipes, as script can read more input than you would expect. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1) HISTORY
The script command appeared in 3.0BSD. BUGS
script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. script is primarily designed for interactive terminal sessions. When stdin is not a terminal (for example: echo foo | script), then the session can hang, because the interactive shell within the script session misses EOF and script has no clue when to close the session. See the NOTES section for more information. AVAILABILITY
The script command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils /util-linux/>. util-linux June 2014 SCRIPT(1)
All times are GMT -4. The time now is 03:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy