[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Redirecting stdout from one Bash script to another

Posted on 2010-11-10
4
Medium Priority
?
490 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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…
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 Month18 days, 20 hours left to enroll

834 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