Solved

Redirecting stdout from one Bash script to another

Posted on 2010-11-10
4
476 Views
Last Modified: 2012-05-10
Hi,

I am wanting to know how it would be possible to write a bash shell script that would pass a set of arguments to a child bash script yet still return the stdout from the child script to the main terminal.

For example, I want to write a bash script which will will auto-populate the arguments (specifically the date argument) of the child script - report_runner.sh, yet still return the run status text that report_runner.sh generates in the terminal:

/../../../current/bin/report/report_runner.sh -e prod-like -r reviewCount 20101011


I want the terminal output from report_runner.sh to be returned to the screen of the parent script calling it. The reason why I can't modify report_runner.sh to populate the date automatically itself is that it is controlled code and I do not want to update this script if I can avoid it.

Suggestions?

Thanks!
0
Comment
Question by:james_j_hedges
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 34105305
Your question is a little unclear.

If the child script sends its output to stdout, then I don't see what you want to change.

Do you want to save the output from the child?  If so, do

/../../../current/bin/report/report_runner.sh -e prod-like -r reviewCount 20101011 | tee /tmp/somelog



0
 

Author Comment

by:james_j_hedges
ID: 34109894
The child script writes text out to the terminal when it is running. When I try and trigger it from a parent script, the text does not get written out to the terminal. Is there any way of still wrapping the child script but still viewing the text in the terminal as it is generated?
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 500 total points
ID: 34109948
If all you are doing in the parent script is calling report_runner.sh and it's not outputing anything, then there must be something specific in report_runner.sh that does that.

It's really hard to know without seeing the report_runner.sh script.
0
 

Author Comment

by:james_j_hedges
ID: 34110764
I managed to sort out the issue. I think there was perhaps something else wrong with the way I was calling the child script which prevented the output from displaying in stdout.

The parent script, 'report_runner_auto.sh' looks like this:

../bin/report/report_runner_auto.sh -e prod-like -r review

#!/bin/bash
cd `dirname $0`

appOptions="${@} $(date -d "yesterday" +%Y%m%d)"
report_runner.sh ${appOptions} 2>&1



Report_runner.sh is now being triggered correctly and output is being returned to stdout.

Thanks for your help.

Cheers.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now