Re: [CentOS] shell script strangeness...

2008-05-16 Thread Ian Blackwell

Craig White wrote:

That works fine one CentOS 5 (double quotes and backtics) but not on
CentOS 4.6

Thanks...I guess it's good enough for now.

Craig

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

  
I can only imagine it is working in 4.6 because the result of grep 
entry_chooser.js /var/log/httpd/access_log is either empty or 1 
word.  The test syntax [ -z xxx ] would report the too many 
arguments error whenever the grep returned more than one word.  You can 
test this at your command line by typing in:-

   [ -z one ]
and
   [ -z one two three four five ]

The first will return false but you'll just see another bash prompt, 
the second will report the too many arguments error.  This is 
certainly the case for me using RHEL4.6, so I would imagine CentOS4.6 
should be the same.  You can also see it explained by these commands and 
results:-

[EMAIL PROTECTED] ~]$ [ -z ]
[EMAIL PROTECTED] ~]$ echo $?
0
[EMAIL PROTECTED] ~]$ [ -z one ]
[EMAIL PROTECTED] ~]$ echo $?
1
[EMAIL PROTECTED] ~]$[ -z one two three four ]
-bash: [: too many arguments
[EMAIL PROTECTED] ~]$ echo $?
2
[EMAIL PROTECTED] ~]$

I hope this helps you understand why it is working on one machine but 
not another.


Ian

PS: I always prefer $(cmd) to backtics for readability.  e.g.

if [ -z $(grep entry_chooser.js /var/log/httpd/access_log) ]

PPS: grep -q works for me on RHEL4.6 and CentOS5.1
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] shell script strangeness...

2008-05-16 Thread Craig White
On Fri, 2008-05-16 at 17:03 +0930, Ian Blackwell wrote:
 Craig White wrote:
  That works fine one CentOS 5 (double quotes and backtics) but not on
  CentOS 4.6
 
  Thanks...I guess it's good enough for now.
 
  Craig
 
  ___
  CentOS mailing list
  CentOS@centos.org
  http://lists.centos.org/mailman/listinfo/centos
 

 I can only imagine it is working in 4.6 because the result of grep 
 entry_chooser.js /var/log/httpd/access_log is either empty or 1 
 word.  The test syntax [ -z xxx ] would report the too many 
 arguments error whenever the grep returned more than one word.  You can 
 test this at your command line by typing in:-
 [ -z one ]
 and
 [ -z one two three four five ]
 
 The first will return false but you'll just see another bash prompt, 
 the second will report the too many arguments error.  This is 
 certainly the case for me using RHEL4.6, so I would imagine CentOS4.6 
 should be the same.  You can also see it explained by these commands and 
 results:-
 [EMAIL PROTECTED] ~]$ [ -z ]
 [EMAIL PROTECTED] ~]$ echo $?
 0
 [EMAIL PROTECTED] ~]$ [ -z one ]
 [EMAIL PROTECTED] ~]$ echo $?
 1
 [EMAIL PROTECTED] ~]$[ -z one two three four ]
 -bash: [: too many arguments
 [EMAIL PROTECTED] ~]$ echo $?
 2
 [EMAIL PROTECTED] ~]$
 
 I hope this helps you understand why it is working on one machine but 
 not another.
 
 Ian
 
 PS: I always prefer $(cmd) to backtics for readability.  e.g.
 
 if [ -z $(grep entry_chooser.js /var/log/httpd/access_log) ]
 
 PPS: grep -q works for me on RHEL4.6 and CentOS5.1

makes a lot of sense - thanks

Craig

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] shell script strangeness...

2008-05-15 Thread Craig White
On my CentOS 4.6 server, this works...

if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]

On my CentOS 5.1 server, this gives me the following error...

./test_file.scr: line 3: [: too many arguments

Can anyone explain why the difference and suggest something that makes
both cases happy?

Thanks

Craig

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] shell script strangeness...

2008-05-15 Thread Ian Blackwell

Craig White wrote:

On my CentOS 4.6 server, this works...

if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]

On my CentOS 5.1 server, this gives me the following error...

./test_file.scr: line 3: [: too many arguments

Can anyone explain why the difference and suggest something that makes
both cases happy?

Thanks

Craig

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

  
Not sure why 4.6 is allowing it, but your if test will be resolving to 
something like this:-
if [ -z this line from your log file and another line and even more 
lines until your if test fails with too many arguments I hope you don't 
want me to keep typing to make the point ]


To fix it, wrap the grep instead double quotes as well as the ticks - e.g.
if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
Then the output from the grep will be seen as one long string, not a 
multitude of words from your log file.


Ian


smime.p7s
Description: S/MIME Cryptographic Signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] shell script strangeness...

2008-05-15 Thread Garrick Staples
On Fri, May 16, 2008 at 02:07:10PM +0930, Ian Blackwell alleged:
 Craig White wrote:
 On my CentOS 4.6 server, this works...
 
 if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
 
 On my CentOS 5.1 server, this gives me the following error...
 
 ./test_file.scr: line 3: [: too many arguments
 
 Can anyone explain why the difference and suggest something that makes
 both cases happy?
 
 Thanks
 
 Craig
 
 ___
 CentOS mailing list
 CentOS@centos.org
 http://lists.centos.org/mailman/listinfo/centos
 
   
 Not sure why 4.6 is allowing it, but your if test will be resolving to 
 something like this:-
 if [ -z this line from your log file and another line and even more 
 lines until your if test fails with too many arguments I hope you don't 
 want me to keep typing to make the point ]
 
 To fix it, wrap the grep instead double quotes as well as the ticks - e.g.
 if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
 Then the output from the grep will be seen as one long string, not a 
 multitude of words from your log file.

Even better is to use 'grep -q' to avoid possibly large string expansions...
   if grep -q entry_chooser.js /var/log/httpd/access_log ;then

-- 
Garrick Staples, GNU/Linux HPCC SysAdmin
University of Southern California

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


pgpF8kEh4F3yE.pgp
Description: PGP signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] shell script strangeness...

2008-05-15 Thread Craig White
On Fri, 2008-05-16 at 14:07 +0930, Ian Blackwell wrote:
 Craig White wrote:
  On my CentOS 4.6 server, this works...
 
  if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
 
  On my CentOS 5.1 server, this gives me the following error...
 
  ./test_file.scr: line 3: [: too many arguments
 
  Can anyone explain why the difference and suggest something that makes
  both cases happy?
 
 Not sure why 4.6 is allowing it, but your if test will be resolving to 
 something like this:-
 if [ -z this line from your log file and another line and even more 
 lines until your if test fails with too many arguments I hope you don't 
 want me to keep typing to make the point ]
 
 To fix it, wrap the grep instead double quotes as well as the ticks - e.g.
 if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
 Then the output from the grep will be seen as one long string, not a 
 multitude of words from your log file.

That works fine one CentOS 5 (double quotes and backtics) but not on
CentOS 4.6

Thanks...I guess it's good enough for now.

Craig

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] shell script strangeness...

2008-05-15 Thread Craig White
On Thu, 2008-05-15 at 22:00 -0700, Garrick Staples wrote:
 On Fri, May 16, 2008 at 02:07:10PM +0930, Ian Blackwell alleged:
  Craig White wrote:
  On my CentOS 4.6 server, this works...
  
  if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
  
  On my CentOS 5.1 server, this gives me the following error...
  
  ./test_file.scr: line 3: [: too many arguments
  
  Can anyone explain why the difference and suggest something that makes
  both cases happy?
  

  Not sure why 4.6 is allowing it, but your if test will be resolving to 
  something like this:-
  if [ -z this line from your log file and another line and even more 
  lines until your if test fails with too many arguments I hope you don't 
  want me to keep typing to make the point ]
  
  To fix it, wrap the grep instead double quotes as well as the ticks - e.g.
  if [ -z `grep entry_chooser.js /var/log/httpd/access_log` ]
  Then the output from the grep will be seen as one long string, not a 
  multitude of words from your log file.
 
 Even better is to use 'grep -q' to avoid possibly large string expansions...
if grep -q entry_chooser.js /var/log/httpd/access_log ;then

for this purpose, -q didn't seem to matter much - thanks

Craig

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos