Results 1 to 2 of 2
I need help trying to figure out how to use grep with an expression that is constantly changing... basically this is what I am trying to do:
Code:
watch "mpstat ...
- 03-20-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 1
Using grep with changing expressions
I need help trying to figure out how to use grep with an expression that is constantly changing... basically this is what I am trying to do:
which, should show me my CPU usage updated every couple seconds. The grep is being used to omit lines that aren't needed (all the useful lines start with the current time.) Problem is, it seems to execute the 'date +%r' command once.Code:watch "mpstat -P ALL | grep -e '`date +%r`'"
I would like grep to execute the date command every time the watch command updates.
EDIT: I've found a workaround by putting the
All in a shell file (that I called cpustat.sh), and then executing watch ./cpustat.shCode:mpstat -P ALL | grep -e "`date +%r`"
Would still like to know if there is an actual solution without having to create a seperate file (and preferably in one line). I have tried using a function to do the mpstat and grep part, but apparently watch doesn't play nice with functions
Last edited by TyPR124; 03-20-2011 at 05:07 AM.
- 03-20-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,977
The bash shell has loops. Run your code in the loop, and sleep between loops for a couple of seconds. You can do this from the command line - a script is not needed. You might even be able to use watch with the loop and eliminate the sleep command.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote