Solved

Redirecting stdout from one Bash script to another

Posted on 2010-11-10
4
475 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 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

19 Experts available now in Live!

Get 1:1 Help Now