Thireus Posted July 16, 2009 Share Posted July 16, 2009 Hi guys, I have a simple question, I want to store the output of the following command: 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: Activity=$(sudo iotop -t 0 3 | grep "load: ") & While $Activity... do blahblah... done But the fact is that nothing can be stored into Activity 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... Link to comment Share on other sites More sharing options...
Thireus Posted July 16, 2009 Author Share Posted July 16, 2009 Ok, here is my code: sudo iotop -t 0 -C 3 | grep "load: " | script.sh script.sh: #!/bin/sh while read data do echo "[$(date +"%D %T")] $data" >> log_activity.txt done But nothing is read Link to comment Share on other sites More sharing options...
Thireus Posted July 16, 2009 Author Share Posted July 16, 2009 SOLVED!!! ... iotop -t 0 -C 3 | grep "load: " --line-buffered | while read data do echo "${data}" #Do whatever you want with ${data} here :) done ... Link to comment Share on other sites More sharing options...
Recommended Posts