Supervise the output of a program using script - linux

How can i write a shell script that can supervise the input and the output of a running script?
I have another script that will generate results. I want something like trigger to run commands when the other script will generate results.

Related

echo map reduce output in shell script using oozie

The .sh script has the following content inside it
echo hbase org.apache.hadoop.hbase.mapreduce.RowCounter TABLE_NAME
The above script will be called by oozie which will capture whatever output the above command emits. The problem is, the above command is executed and no output gets echoed since all the output is happening in the background. How to capture those background output and echo it using shell script?
First thing first, you need to have <capture-output/> in the Oozie Shell action.
Also to capture the output in Oozie shell action, the script need to be something like the following:
set var=`hbase org.apache.hadoop.hbase.mapreduce.RowCounter TABLE_NAME`
echo "capture_var=$var"
After you do this, the variable will be available to be passed/used within Oozie using:
${wf:actionData('shellscriptoozieactionname')['capture_var']}

How do I write the "script" bash command in a python script to log my output

I am trying to log my python output using bash command "script". The reason that I am doing this is because there is a piece of information that I needed from the program that I am running. But it is a Nonetype which was just printed in the console. I need that piece of information, but there is no way pulling this info out besides manually copy and paste it to my output file.
So I thought I can use "script" in bash to log everything in the console to a txt file and from there I kinda cheated and converted this Nonetype output in the console to a txt file. But now I am trying to make this process automatic. So I started testing this idea out, and I came across this issue: once the script reaches the line to call the "script" command, it spawns a new shell, so it was not able to reach the rest of the code.
Below is a piece of code for testing purpose.
from subprocess import call
call(['script', 'test.txt']) # call script in the bash shell
print('Hello World') # using python to print hello world
call(['exit']) # logout the shell
I am wondering is there any way that can call "script" command and return to the rest of the script?

send commands to application with bash script

Is it possible to send commands to a running script with a bash script in linux?
for example say that I have a python script with a couple of inputs, can I somehow use a bash script to handle these inputs?

how to run a python script as soon as another process ends

there is a process running that will write some output to a set of files. I wrote a python script that will make a copy of these output files in another directory. Right now I can simply run the python script when I notice the other process is done. How can I get this script to be run automatically when the other process is done?
I don't have control over the other process's source code. Messing with the source code might make the results file inadmissible, so I'd rather not touch it at all.
I am running Python 2.7.1 in an Ubuntu 11.x machine.
You don't tell much about what is the program running before the Python script, but if it is or you can convert to a shell script, you can use this syntax:
$ first-script.sh && python-script.sh
The && operator means that if the first script finished successfully, run the second afterwards.
Of course, you could invoke the python interpreter with your script directly as the 2nd script. Here I assume that it is wrapped in a Bash script.

No output when running jar from shell script

I am running a jar-file in a shell script calling hierarchy. I want to redirect the output from executing the jar file to my logfile "loga.log" but this does only work when I run this script with "sh"-command.
My calling hierarchy basically looks like this:
Script A calls script B with:
/path/to/script/scriptb.sh &> /path/to/logs/loga.log
Script B calls script C with:
/path/to/script/scriptc.sh > /path/to/logs/logb.log
Script C executes jar-file with:
java -Xms512m -Xmx1280m -Djava.awt.headless=true -jar /path/to/jar/thejar.jar > /path/to/logs/stdout.log #2>/path/to/logs/stderr.log
The first script is started by command line with:
sh /path/to/scripts/scripta.sh
and then I get written my output as wanted to the loga.log-file. When I start the script via:
/path/to/scripts/scripta.sh
this doesn't work and the output is displayed in the console. Unfortunately I am not able to use the sh command because these scripts must be triggered by a UC4-job system which calls this script without using sh. Calling the second script using "sh" inside the first one doesn't work eigther.
How can I edit the scripts to be able to log all output to the specified logfile when running the first one via the above command (without sh)?
Thanks in advance,
Martin

Resources