Keeping std & err outputs alive and feed one log file in a one-shot way


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Keeping std & err outputs alive and feed one log file in a one-shot way
# 1  
Old 11-23-2012
Question Keeping std & err outputs alive and feed one log file in a one-shot way

Bonjour,

I have a large script with a lot of print statements and misc commands. Standard and error outputs are redirected like into the following code :
Code:
#!/usr/bin/ksh

LOG=/<some dir>/log
> $LOG
exec >>${LOG} 2>>${LOG}

print aaaaa
print bbbbb
print ccccc
...
some_cmd

That way, standard and error outputs are added to the log file without appending >> {LOG} 2>>{LOG} after each print statement or command.

But now, we must execute these scripts via a new scheduler (VTOM) and still keep our ${LOG} file feeded.
The problem is that VTOM feeds its own logs with standard and error outputs so exec ... line must be commented.

My question : is there anyway to keep standard and error outputs alive for VTOM usage and feed too our UNIX log without appending redirections after each print statements and commands ?

ps : i've searched around tee command but without any good results. Maybe additional file descriptors may be used, but i've never worked with them.
# 2  
Old 11-23-2012
Do you mind explaining me what was wrong with just:
Code:
 your_script >>/path2log/logfile  2>&1

In order to answer you...
# 3  
Old 11-23-2012
Quote:
Originally Posted by vbe
Code:
your_script >>/path2log/logfile  2>&1

That way I do not have any terminal output Smilie
# 4  
Old 11-23-2012
Sorry when you say scheduler to me that means batchs... and so no terminals are attached... I understand better now... considered using tail -f /.../logfile ?
# 5  
Old 11-23-2012
I guess I've found a solution using a wrapper :
Code:
#!/usr/bin/ksh

LADATE=$(date +'%Y%m%d_%H%M%S')
SCRIPT=$(basename $0)
REPRISE=${1:-debut}
FIN=${2:-fin}
PID=$$

CUR_DIR=/home/dpi/patrick/prj_mksysb
SERVER=$3

REPLOG=$CUR_DIR     # pour la phase de tests
REPLOGCTRL=$CUR_DIR #           "
LOG=${REPLOG}/${SCRIPT%.*}_${PID}_${LADATE}.log
LOGCTRL=${REPLOGCTRL}/${SCRIPT%.*}_${SERVER}.log

> ${LOG}
> ${LOGCTRL}

. ${CUR_DIR}/tstout.ksh $1 $2 $3 2>&1 | tee ${LOG}

exit

which calls tstout.ksh program :
Code:
#!/usr/bin/ksh

print $1" "$2" "$3

print aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
print bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
print cccccccccccccccccccccccccccccccccccccccccccccccccc

I launch it using : ./wrapper.ksh linux openbsd freebsd

And it works fine : it feeds my log files and terminal outputs are available for the scheduler. I tests it into the scheduler, it's OK too.

It's not completely clear in my mind, but job is done
Smilie
This User Gave Thanks to Fundix For This Post:
# 6  
Old 11-23-2012
Thanks for sharing... When I will have a bit more time I will look more deeply the code...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh view std err state

I would like to know if a command works. "command" 2>/dev/null When I issue the command, the error is suppressed. How can I tell whether there was an error? (3 Replies)
Discussion started by: robin_simple
3 Replies

2. Shell Programming and Scripting

Ksh script: std Out/err

Hello gurus, this is part of my script: ls -1 ${MyFile} >> ${dir_log}ListFile${Now}.tmp FILENUM=`cat ${dir_log}ListFile${Now}.tmp| wc -l | awk '{print $1}'`>> /dev/null if then writeError "ERRORE: no file in directory for type ${FileName}!" >> ${LogFileName} Close 1 fi... (7 Replies)
Discussion started by: GERMANICO
7 Replies

3. Solaris

keeping a process alive ?

Hello guys, I have one script running that I need to keep it running 24x7 so I'd like to know how can I implement a sort of monitoring process I mean if for some reason this process dies somehow it gets automatically started again. Thanks. (8 Replies)
Discussion started by: cerioni
8 Replies

4. Shell Programming and Scripting

filter input & outputs to another file

Hello All, I am stuck with the follwing problem , pls give me some advice.. Input file: input clock; input reset; \\reset all input yuv; //input comment output sur; output sud; output vtua; output tur; input ebi; //output comment The input file... (1 Reply)
Discussion started by: user_prady
1 Replies

5. Shell Programming and Scripting

How to store the outputs of a shell script inside a log file???

My shell script file name is test.sh and the contents of this test.sh file are ps_file="package1.ps" echo $ps_file ps_file1=`echo $ps_file| sed "s/.ps//g"` echo $ps_file1 ps2pdf -dSAFER -sPAPERSIZE=a4 /tmp/A380_RFS24/amm_r0_ps/$ps_file1.ps /tmp/A380_RFS24/amm_r0_pdf/$ps_file1.pdf Now i... (2 Replies)
Discussion started by: sunitachoudhury
2 Replies

6. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

7. Shell Programming and Scripting

How to redirect std err and out to log file for multi-commands?

The following command does not work under cygwin bash. ant debug >log 2>&1 && ant image >>log 2>>&1 & pid=$! It gives the error "-bash: sysntax error near unexpected token '&'". Is there a way I can redirect std output and std error to file "log" for both the commands "ant debug" and "ant... (1 Reply)
Discussion started by: siegfried
1 Replies

8. UNIX for Dummies Questions & Answers

Keeping cron jobs alive...?

Hi, I'm very new to Unix so please bear with me... :) Here is my requirement: I need to create a cron job to run two different scripts at 1 a.m. every day. Here's what I did: I used the "crontab -e" command and created a crontab file using the vi editor. When I exit the editor using... (3 Replies)
Discussion started by: yogiB
3 Replies

9. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question