1,105,578 Community Members

Subshell Problem, syntax error...Help please!

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
vgersh99
Newbie Poster
21 posts since Nov 2004
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hmm, still gave me the same error. Any suggestions on an editor I can use that would give me more feedback? Thanks again...

Member Avatar
vgersh99
Newbie Poster
21 posts since Nov 2004
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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 ')'

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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:

Member Avatar
vgersh99
Newbie Poster
21 posts since Nov 2004
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

put the whole script in debug:

substitue:

#!/bin/ksh

with:

#!/bin/ksh
set -x

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

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

put the whole script in debug:

substitue:

#!/bin/ksh

with:

#!/bin/ksh
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...

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
vgersh99
Newbie Poster
21 posts since Nov 2004
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

your culprit is this:

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?

set stat = ./pcx /tmp/kismet_dump $1
Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

your culprit is this:

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?

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?

Member Avatar
vgersh99
Newbie Poster
21 posts since Nov 2004
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

if that's the assumption, then the way to implement it is:

./pcx /tmp/kismet_dump $1

stat = ${?}
.....

This is assumpting './pcx' [whatever that is] returns properly formated return codes.

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

excellent, thank you...now to figure out why the while loop is not working...

Member Avatar
vgersh99
Newbie Poster
21 posts since Nov 2004
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

good luck!

Member Avatar
nitewolf_9
Newbie Poster
8 posts since Dec 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

your help is much appreciated btw, thanks again for your patience...

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article