help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to set up a repeat check procedure?


From: Greg Wooledge
Subject: Re: [Help-bash] how to set up a repeat check procedure?
Date: Fri, 30 Dec 2011 09:23:14 -0500
User-agent: Mutt/1.4.2.3i

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.sh

There 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
done

> Last 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' ]

is exactly equivalent to:

 while [ 'HASKJDKHASKDHKJSAHDHSKJAHDHASLD' ]

which is exactly equivalent to:

  while true

You were not running qstat or grep at all.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]