Redirecting to standard output from within called script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting to standard output from within called script
# 1  
Old 07-02-2006
Redirecting to standard output from within called script

Hi,

How to achieve this? Let us assume the following:

There are 2 scripts a.ksh and b.ksh

$ cat a.ksh
sh b.sh 2>&1 >> /work/log/a_log.txt

$ cat b.sh
echo "abcd"

My requirement is, is there a way to display this abcd in standard output also alongside of writing into a_log.txt? Please help me out in this. Appreciate your help.

Regards,
Vignesh
# 2  
Old 07-02-2006
Hi,

Try the following:
sh b.sh | tee -a /work/log/a_log.txt

"tee -a " write to the standart output and to a log file parallely.

Regards,
Nir
# 3  
Old 07-03-2006
Hi Nir,

But the problem is the script (here b.sh) is a common script that is called by a lot of scripts that are coded in this way. It is difficult to modify those scripts. So please suggest me if there is a way to do that in b.sh itself.

Thanks,
Vignesh
# 4  
Old 07-03-2006
Re:

Hi,


Make the following changes in b.sh

echo "abcd" | tee /dev/tty

This should do the trick and you would get the data in the file as well as standard output.


PS: Sorry, i just noticed that you wanted changes done in a.sh and not b.sh. Please ignore this one.

Last edited by vish_indian; 07-03-2006 at 06:09 AM..
# 5  
Old 07-03-2006
Quote:
Originally Posted by vigneshra
$ cat a.ksh
sh b.sh 2>&1 >> /work/log/a_log.txt
Use:
Code:
sh b.sh 2>&1| tee -a /work/log/a_log.txt

# 6  
Old 07-03-2006
Question

Hi,

I want the change to be done in b.ksh only.

echo "abcd" | tee /dev/tty does not seem to be working.

Do you have any other suggestions? Smilie

Thanks,
Vignesh
# 7  
Old 07-04-2006
Then try:
Code:
$ cat a.ksh
sh b.sh 2>&1 |tee -a /work/log/a_log.txt
2>&2
# rest here

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

2. Shell Programming and Scripting

Redirecting command output to a file in a shell script

Hello All, I have some unique requirement. I have written a very lengthy script which calls number of resource script to execute a particular task. What I want is output of each command(called from main script and resource scripts) should go to a... (3 Replies)
Discussion started by: anand.shah
3 Replies

3. Shell Programming and Scripting

Redirecting output for the entire script

Hi All, I am trying to redirect output for every line in a korn shell script that is going to generate output and append it to a log file. I have been doing this after EACH and every line that is going to produce output: command 1 >> test.log command 2 >> test.log command 3 >>... (5 Replies)
Discussion started by: MIA651
5 Replies

4. Shell Programming and Scripting

Redirecting script output to terminal

When ever i started my terminal,Every time I have to change the directory like "cd user/documents/ravi/folder2/folder3" Without typing this entire command every time ,I placed "alias c='cd user/documents/ravi/folder2/folder3'" in .bash_profile file. so that i can able to execute command 'c'... (6 Replies)
Discussion started by: Raviteja saddal
6 Replies

5. UNIX for Dummies Questions & Answers

redirecting script output

Hello, I am interested in taking the output from a script i wrote and using it as input to a different script i wrote. So for example i want to take the output from program2 and use it as a parameter for program1. I didnt think i could use the >> symbols because i think that is just for .txt... (4 Replies)
Discussion started by: GmGeubt
4 Replies

6. UNIX for Dummies Questions & Answers

redirecting the script output to more than 1 file

Hi, I want to redirect my script output to more than one file without printing the result to the screen. How to do that? ex: echo "hi" >> a.txt b.txt cat a.txt hi b.txt :confused: (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

7. Shell Programming and Scripting

Redirecting standard error issues.

Hello Friends, Good Day. I am trying to redirect a standard error to the bit bucket(/dev/null) but it is not working. Though, it is working fine in redirecting the standard output. Below is the output of my script without any redirection: $ ./CheckVSSLocks.sh... (16 Replies)
Discussion started by: singh.chandan18
16 Replies

8. UNIX for Dummies Questions & Answers

Redirect Standard output and standard error into spreadsheet

Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway? Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Discussion started by: killaram
6 Replies

9. Shell Programming and Scripting

redirecting SQL output from within a shell script

Hi all I would like to open a SQL session from within a shell script and then redirect the output of the SQL command to a file. e.g. #!/bin/bash sqlplus "/ as sysdba" <<EOF @$HOME/recovery_space.sql EOF I want to redirect the output of the SQL command to a temp file, because... (2 Replies)
Discussion started by: soliberus
2 Replies

10. Shell Programming and Scripting

file content to standard output from a script

hi folks how do i output contents of file in standard output. in my script, i say x=`cat filename' echo $x below is the actual file *********** asda afdf fdf sdf dsfsdfsd fds dsfdfsdfsdg ssgd sgdg sdfsdgfsdg dgfd gsfd gs sdg sfdg s in my script, i am trying to output the... (4 Replies)
Discussion started by: bryan
4 Replies
Login or Register to Ask a Question