Solved

Redirecting stdout from one Bash script to another

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerShell Get-Help 10 80
Unix/bash: scripted arithmetic 13 101
Powershell to pull all Service accounts 1 63
AWK How do I reorder the columns in a csv 7 45
This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…

860 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