|
From: | lina |
Subject: | Re: [Help-bash] how to set up a repeat check procedure? |
Date: | Fri, 30 Dec 2011 23:32:56 +0800 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111114 Icedove/3.1.16 |
On Friday 30,December,2011 10:23 PM, Greg Wooledge wrote:
I do have lots to learn, I wished to grep " R " at that time, didn't realize such mistake.On Fri, Dec 30, 2011 at 10:11:41PM +0800, lina wrote:#!/bin/bash while [ 'qstat | grep REM | grep R' ]; do sleep 10; done ./rem_extend.shThere are some mistakes here. The most important is that you messed up the quotes -- I believe you intended to use backquotes, not single quotes. However, even if you fix those, there are still more mistakes. For example, any line that matches REM is also going to match R, so the second grep is pointless. Moreover, if you're just trying to see whether a grep command matches something or not, you don't even *want* to quote it, or capture it, nor do you want to use a [ command in any way. I believe what you want is: while qstat | grep -q REM do sleep 10 doneLast time I left the computer to sleep, it's supposed to run the following script in 2 hours, but morning I found it's not. kinda of totally sleep over?The way you wrote the code, the [ command *always* returned true, because you were checking the length of a string literal. while [ 'qstat | grep REM | grep R' ]
-bash-3.2$ while [ ! qstat | grep -q nvt_em_16 ]; do echo finished ; done; echo running
-bash: [: missing `]' grep: ]: No such file or directory runningBefore due to above error report, so I added the ' ', thanks for pointing out the mistakes.
I am still lack of understanding above error report, Your way works,-bash-3.2$ while ! qstat | grep -q nvt_em_16 | grep R ; do echo finished ; done; echo running
running suppose I have a bit long conditions, do I also no need [ ] for while?$ while ! qstat | grep -q nvt_em_16 && 2 -lt 4 && 1; do echo finished ; done; echo running
running I tried, seems works?! Sorry and thanks,
is exactly equivalent to: while [ 'HASKJDKHASKDHKJSAHDHSKJAHDHASLD' ] which is exactly equivalent to: while true You were not running qstat or grep at all.
Best regards,
[Prev in Thread] | Current Thread | [Next in Thread] |