Re: Shell script anomaly SOLVED

2002-05-15 Thread Alex Malinovich
On Wed, 2002-05-15 at 06:53, Miquel van Smoorenburg wrote:
> In article <[EMAIL PROTECTED]>,
> Sure. If your script is called something like "check-xscreensaver"
> the grep finds the script itself.
> 
> Why not use "pidof xscreensaver", see man pidof(8)

That was it! The script name was 40xscreensaver. I remembered to put in
the [x] so that the grep command wouldn't show up, but I hadn't thought
of the script that it was being called from. Thanks. :)

-Alex


signature.asc
Description: This is a digitally signed message part


Re: Shell script anomaly

2002-05-15 Thread Andreas Nowack
On 14 May 2002, Alex Malinovich wrote:

> if ps -A |grep -q "[x]screensaver"; then xscreensaver-command -activate
> else xscreensaver& xscreensaver-command -activate; fi
>
> However, if I put that exact line into a shell script and run it, the if
> ALWAYS gets evaluated as true. Any ideas?

I would test the output of grep. So change the line to
  if ps -A |grep -q "[x]screensaver" > /tmp/grep_output; then ...
and look at /tmp/grep_output and you will see why grep returns true.

Best regards,
  Andreas


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: Shell script anomaly

2002-05-15 Thread Miquel van Smoorenburg
In article <[EMAIL PROTECTED]>,
Alex Malinovich  <[EMAIL PROTECTED]> wrote:
>I'm sure that I might be missing something obvious here, but after a few
>hours I still haven't figured it out. I'm writing a script to detect
>whether xscreensaver is running and activate it if it is. If not, it
>launches the daemon first and then activates. From the command line, the
>following returns the correct exit codes:
>
>if ps -A |grep -q "[x]screensaver"; then xscreensaver-command -activate
>else xscreensaver& xscreensaver-command -activate; fi
>
>However, if I put that exact line into a shell script and run it, the if
>ALWAYS gets evaluated as true. Any ideas?

Sure. If your script is called something like "check-xscreensaver"
the grep finds the script itself.

Why not use "pidof xscreensaver", see man pidof(8)

Mike.
-- 
"Insanity -- a perfectly rational adjustment to an insane world."
  - R.D. Lang


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: Shell script anomaly

2002-05-15 Thread Tom Cook
On  0, Alex Malinovich <[EMAIL PROTECTED]> wrote:
> On Tue, 2002-05-14 at 22:06, Craig Dickson wrote:
> > I cannot reproduce your symptoms. Whether I type your code in at the
> > shell prompt or run it in a script, it always behaves correctly.
> > 
> > You don't say what shell you're using (or what version); my tests were
> > performed using the version of bash 2.05a.0(1)-release from the Sid
> > package bash_2.05a-11.
> 
> GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu)
> 
> as returned by bash --version
> 
> I just tried something else and now it's even stranger. If I don't
> specify a shell in the script, it works correctly. However using
> #!/bin/sh or #!/bin/bash results in errors. That's even stranger than
> the exit code being returned incorrectly.

ls -l /bin/sh /bin/bash

what does it say?  Are they the same executable as reported by:

grep $USER /etc/passwd

or whatever passwd you use?

Tom
-- 
Tom Cook
Information Technology Services, The University of Adelaide

Never be irreplacable:  If you are irreplacable then you are unpromotable.

Get my GPG public key: 
https://pinky.its.adelaide.edu.au/~tkcook/tom.cook-at-adelaide.edu.au


pgpLftQ85GQXC.pgp
Description: PGP signature


Re: Shell script anomaly

2002-05-14 Thread Alex Malinovich
On Tue, 2002-05-14 at 22:06, Craig Dickson wrote:
> I cannot reproduce your symptoms. Whether I type your code in at the
> shell prompt or run it in a script, it always behaves correctly.
> 
> You don't say what shell you're using (or what version); my tests were
> performed using the version of bash 2.05a.0(1)-release from the Sid
> package bash_2.05a-11.

GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu)

as returned by bash --version

I just tried something else and now it's even stranger. If I don't
specify a shell in the script, it works correctly. However using
#!/bin/sh or #!/bin/bash results in errors. That's even stranger than
the exit code being returned incorrectly.

-Alex


signature.asc
Description: This is a digitally signed message part


Re: Shell script anomaly

2002-05-14 Thread Tom Cook
On  0, Alex Malinovich <[EMAIL PROTECTED]> wrote:
> I'm sure that I might be missing something obvious here, but after a few
> hours I still haven't figured it out. I'm writing a script to detect
> whether xscreensaver is running and activate it if it is. If not, it
> launches the daemon first and then activates. From the command line, the
> following returns the correct exit codes:
> 
> if ps -A |grep -q "[x]screensaver"; then xscreensaver-command -activate
> else xscreensaver& xscreensaver-command -activate; fi
> 
> However, if I put that exact line into a shell script and run it, the if
> ALWAYS gets evaluated as true. Any ideas?

It Works For Me (TM).  As someone else has asked, which shell are you
using?  This works for me in bash 2.05a.0(1)-release
(i386-pc-linux-gnu).


Maybe you always have xscreensaver running?


Of course you don't, do you?  Cull the -q and check.

Regards,
Tom
-- 
Tom Cook
Information Technology Services, The University of Adelaide

"Other people's priorities are endlessly odd."
- Kingsley Amis

Get my GPG public key: 
https://pinky.its.adelaide.edu.au/~tkcook/tom.cook-at-adelaide.edu.au


pgpV5aQBrXQfZ.pgp
Description: PGP signature


Re: Shell script anomaly

2002-05-14 Thread Craig Dickson
begin  Sean 'Shaleh' Perry  quotation:

> I could be wrong but I think the if is checking whether ps returned
> successfully or not.

I don't think so. It should be checking the return code of the final
command in the pipe, which in this case is grep.

Craig


pgppIOVwsLwO9.pgp
Description: PGP signature


Re: Shell script anomaly

2002-05-14 Thread Sean 'Shaleh' Perry

On 15-May-2002 Alex Malinovich wrote:
> I'm sure that I might be missing something obvious here, but after a few
> hours I still haven't figured it out. I'm writing a script to detect
> whether xscreensaver is running and activate it if it is. If not, it
> launches the daemon first and then activates. From the command line, the
> following returns the correct exit codes:
> 
> if ps -A |grep -q "[x]screensaver"; then xscreensaver-command -activate
> else xscreensaver& xscreensaver-command -activate; fi
> 
> However, if I put that exact line into a shell script and run it, the if
> ALWAYS gets evaluated as true. Any ideas?
> 
> -Alex
> 

I could be wrong but I think the if is checking whether ps returned
successfully or not.  Try putting the ps|grep output into a variable and
checking whether the variable is empty or not.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: Shell script anomaly

2002-05-14 Thread Craig Dickson
begin  Alex Malinovich  quotation:

> I'm sure that I might be missing something obvious here, but after a few
> hours I still haven't figured it out. I'm writing a script to detect
> whether xscreensaver is running and activate it if it is. If not, it
> launches the daemon first and then activates. From the command line, the
> following returns the correct exit codes:
> 
> if ps -A |grep -q "[x]screensaver"; then xscreensaver-command -activate
> else xscreensaver& xscreensaver-command -activate; fi
> 
> However, if I put that exact line into a shell script and run it, the if
> ALWAYS gets evaluated as true. Any ideas?

I cannot reproduce your symptoms. Whether I type your code in at the
shell prompt or run it in a script, it always behaves correctly.

You don't say what shell you're using (or what version); my tests were
performed using the version of bash 2.05a.0(1)-release from the Sid
package bash_2.05a-11.

Craig


pgpwxMQkKNIZJ.pgp
Description: PGP signature


Shell script anomaly

2002-05-14 Thread Alex Malinovich
I'm sure that I might be missing something obvious here, but after a few
hours I still haven't figured it out. I'm writing a script to detect
whether xscreensaver is running and activate it if it is. If not, it
launches the daemon first and then activates. From the command line, the
following returns the correct exit codes:

if ps -A |grep -q "[x]screensaver"; then xscreensaver-command -activate
else xscreensaver& xscreensaver-command -activate; fi

However, if I put that exact line into a shell script and run it, the if
ALWAYS gets evaluated as true. Any ideas?

-Alex



signature.asc
Description: This is a digitally signed message part