Subshell Problem, syntax error...Help please!

Reply

Join Date: Dec 2004
Posts: 8
Reputation: nitewolf_9 is an unknown quantity at this point 
Solved Threads: 0
nitewolf_9 nitewolf_9 is offline Offline
Newbie Poster

Subshell Problem, syntax error...Help please!

 
0
  #1
Dec 6th, 2004
Hello, I am getting a syntax error with a shell script of mine that is eluding me...I am pretty new to this so if someone could help me out I'd appreciate it. Here is the part of the script that is throwing the error:

#!/bin/ksh
# Kismet/PCX Loader
#

.
.
.


set count = 0 
set stat = 1

# while output pipe cannot be opened, keep trying to open it.  stop after 10 seconds (5 tries)
# run the two concurrently
#  /root/kismet-2004-04-R1/kismet_server 
# kismet_server & bash ; cd /home/bang/dev/3.x/rtpcx/bin/x86_og/
(kismet_server) & 
(
cd /home/bang/dev/3.x/rtpcx/bin/x86_og/
while [ $stat -gt 0 ] 
do
  # echo "+++++  GOT IN HERE +++++"
  set stat = ./pcx /tmp/kismet_dump $1
  # wait for 4 seconds
  sleep 4 
  set count = 'expr $count + 1' 
  if [ $count -eq 5 ]; then
     echo "ERROR: could not open Kismet output pipe."
     break
  else  
      if [ $count -ne 1 ]; then
	  echo "retrying Kismet output pipe..."
      else
	  echo "opening Kismet output pipe..."
      fi
  fi
done
)      # <---  *** ERROR OCCURS HERE, COMPLAINS ABOUT ")" ***

wait  
.
.
.

It complains about the closing ) after the while loop.
The exact error is:
"./wireless_pcx_shell[33]: [: 0: unexpected operator/operand"
Is there something that I am doing wrong here? Any help would be great, thanks everyone.
Last edited by alc6379; Dec 6th, 2004 at 5:24 pm. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: vgersh99 is an unknown quantity at this point 
Solved Threads: 0
vgersh99's Avatar
vgersh99 vgersh99 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #2
Dec 6th, 2004
change:
set count = 'expr $count + 1'

TO:

count = $(( count + 1 ))

This is somewhat cosmetic

You need to check your balanced parents BEFORE the offending line. So far I don't see anything being unbalanced, but doing it with a real editor could be helpful.
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 8
Reputation: nitewolf_9 is an unknown quantity at this point 
Solved Threads: 0
nitewolf_9 nitewolf_9 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #3
Dec 6th, 2004
hmm, still gave me the same error. Any suggestions on an editor I can use that would give me more feedback? Thanks again...
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: vgersh99 is an unknown quantity at this point 
Solved Threads: 0
vgersh99's Avatar
vgersh99 vgersh99 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #4
Dec 6th, 2004
using 'vi':
1. place your cursor on the closing ')' on the offinding line
2. hit '%' - the cursor will move to the MATCHING '(' - make sure it is what it's supposed to be
3. do the same for any preceeding '(' or ')'
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 8
Reputation: nitewolf_9 is an unknown quantity at this point 
Solved Threads: 0
nitewolf_9 nitewolf_9 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #5
Dec 6th, 2004
the parentheses seem to be matching
ie, vi matches the ) in question with the ( after the "(kismet_server) &"


So parentheses matchin is definitly not the issue...quite strange :eek:
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: vgersh99 is an unknown quantity at this point 
Solved Threads: 0
vgersh99's Avatar
vgersh99 vgersh99 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #6
Dec 6th, 2004
put the whole script in debug:

substitue:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/ksh

with:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/ksh
  2. set -x

see the script execute - maybe it'll give you a hint.
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 8
Reputation: nitewolf_9 is an unknown quantity at this point 
Solved Threads: 0
nitewolf_9 nitewolf_9 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #7
Dec 7th, 2004
Originally Posted by vgersh99
put the whole script in debug:

substitue:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/ksh

with:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/ksh
  2. set -x

see the script execute - maybe it'll give you a hint.

Okay, so I ran it in debug mode, and it got to the kismet_server command, started to run that, then did the cd /home/bang/... command, then the command "[ -gt 0 ]" was run, then it throws the same error (./wireless_pcx_shell[37]: [: 0: unexpected operator/operand) and then does the wait command. I'm not sure why that parentheses is still throwing an error, doesn't seem to make any sense. Any other suggestions? Thanks for helping me...
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 8
Reputation: nitewolf_9 is an unknown quantity at this point 
Solved Threads: 0
nitewolf_9 nitewolf_9 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #8
Dec 7th, 2004
okay, I just commented out everything and narrowed it down to a problem with the while loop...just the while loop. Any obvious syntax error I'm missing?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: vgersh99 is an unknown quantity at this point 
Solved Threads: 0
vgersh99's Avatar
vgersh99 vgersh99 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #9
Dec 7th, 2004
your culprit is this:
Shell Scripting Syntax (Toggle Plain Text)
  1. while [ $stat -gt 0 ]

seem that '$stat' does not get assigned any number. When the comparison is made there's nothing to compare against '0'.

instead of using
set count = 0
set stat = 1

use:
typeset -i count = 0
typeset -i stat=1

also, what is the meaning of this?
Shell Scripting Syntax (Toggle Plain Text)
  1. set stat = ./pcx /tmp/kismet_dump $1
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 8
Reputation: nitewolf_9 is an unknown quantity at this point 
Solved Threads: 0
nitewolf_9 nitewolf_9 is offline Offline
Newbie Poster

Re: Subshell Problem, syntax error...Help please!

 
0
  #10
Dec 7th, 2004
Originally Posted by vgersh99
your culprit is this:
Shell Scripting Syntax (Toggle Plain Text)
  1. while [ $stat -gt 0 ]

seem that '$stat' does not get assigned any number. When the comparison is made there's nothing to compare against '0'.

instead of using
set count = 0
set stat = 1

use:
typeset -i count = 0
typeset -i stat=1

also, what is the meaning of this?
Shell Scripting Syntax (Toggle Plain Text)
  1. set stat = ./pcx /tmp/kismet_dump $1

I'm trying to have stat be whether or not the ./pcx ... command was executed or not. Wont it return a 0 if it completes and a non zero value if it throws an error? For some reason I am operating on that assumption. Is there a better way to have my script stay in that loop and keep trying that command until it succeeds or times out?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC