Help - Search - Members - Calendar
Full Version: [How To?] Run shell script and get output into another shell.
InsanelyMac Forum > Apple World > Mac Programming and Development > AppleScript and Automator
Thireus
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 sad.gif
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... sad.gif
Thireus
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 sad.gif
Thireus
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
...


smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.