?
Solved

Redirecting stdout from one Bash script to another

Posted on 2010-11-10
4
Medium Priority
?
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 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 2000 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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

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 …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 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