[How To?] Run shell script and get output into another shell.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [How To?] Run shell script and get output into another shell.
# 1  
Old 07-16-2009
[How To?] Run shell script and get output into another shell.

Hi guys,

I have a simple question, I want to store the output of the following command:

Quote:
sudo iotop -t 0 -C 3 | grep "load: "
As you can see it is running all the time, and we get a new line every 3sec.

I just want to store these new lines into a single variable, so I can use it into a script.

To clear the screen, and do not print lines after the others when iotop is running just delete "- C".

I DO NOT WANT TO STORE THE OUTPUT ON THE DRIVE!!!
I DO NOT WANT TO KILL IOTOP, IT MUST BE RUNNING ALL THE TIME IN BACKGROUND!!!

The idea is to do not write on the drive! Just store the output into a single variable called $Activity.

For example:

Code:
Activity=$(sudo iotop -t 0 3 | grep "load: ") &

While $Activity... do blahblah... done

But the fact is that nothing can be stored into Activity Smilie
So I have tried to know if something can be done to read the last output of a specified PID. But I need help on that point too :-/ I don't know how to do it.

Please help... Smilie

---------- Post updated at 09:57 AM ---------- Previous update was at 02:02 AM ----------

Ok, here is my code:

Code:
sudo iotop -t 0 -C 3 | grep "load: " | script.sh

script.sh:

Code:
#!/bin/sh

  while read data
  do
      echo "[$(date +"%D %T")] $data" >> log_activity.txt
  done

But nothing is read Smilie
# 2  
Old 07-16-2009
Maybe "mkfifo" could help you in this case.
# 3  
Old 07-16-2009
Quote:
Originally Posted by thanhdat
Maybe "mkfifo" could help you in this case.
Sorry but,
Quote:
I DO NOT WANT TO STORE THE OUTPUT ON THE DRIVE!!!
Smilie

---------- Post updated at 03:03 PM ---------- Previous update was at 01:43 PM ----------

Sorry, my mistake, a fifo seems to do not write the output on the drive. Can you confirm?
# 4  
Old 07-16-2009
What mkfifo does is it creates a pipe into which you can send your data from
Code:
sudo iotop -t 0 -C 3 | grep "load: "

and than read from it. No data is actually stored on the disk except for the pipe itself.

See http://en.wikipedia.org/wiki/FIFO_(computing)
# 5  
Old 07-16-2009
Ok great, but now the problem is the same.

I cannot play with the fifo outputs!

Code:
mkfifo my_pipe
sudo iotop -t 0 -C 3 > my_pipe

And then from another shell:

Code:
cat my_pipe

Gives the same problem... I mean I cannot store the disk activity into a single variable.

---------- Post updated at 04:44 PM ---------- Previous update was at 03:32 PM ----------

SOLVED!!!

Code:
...
iotop -t 0 -C 3 | grep "load: " --line-buffered |  while read data
do
    echo "${data}"
    #Do whatever you want with ${data} here :)
done
...

Smilie

---------- Post updated at 04:45 PM ---------- Previous update was at 04:44 PM ----------

But yeah fifo was working too Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies

4. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

5. Fedora

Re: How To Run Shell Script

Hi , I Have Installed Red Hat Linux 5(Guest O.S) In Vmware And Host O.S Is Windows 7 .I Am Unable To Run Script File In It Is Giving Error E32: No File Name.For All Basic Commands It's Working Fine Like Cat ,Cmp.,etc . I Logging As Root User And Working Under The Directory I Am Using... (3 Replies)
Discussion started by: anudeepkumar123
3 Replies

6. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

7. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies

8. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies

9. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question