6

I am following a tutorial on how to run a reverse ssh tunnel which is found at http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling Issue I am having is when I run the tunneling.sh script:

#!/bin/sh
a=`ps -ef | grep 19999 | grep -v grep`
if [ ! "$a" ]; then
    ssh -fN -R 19999:localhost:22 <middle-usename>@<middle-hostname>
fi

I receive this error:

tunnel2.sh: 2: tunnel2.sh: a: not found

EDIT:

I changed shebang to #!/bin/bash

now I get this error:

tunnel2.sh: 2: tunnel2.sh: pi: not found
Richard
  • 15,152
  • 31
  • 85
  • 111

2 Answers2

12

Don't specify #!/bin/sh in your "shebang" line if you're going to use bash features. If you want bash, ask for bash.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
  • thanks Paul, please understand that I am knowledgeable in other languages but I am just starting out in shell scripting. I did try to change the shebang line as suggest but I get a new error as shown above – Richard Dec 04 '12 at 18:46
0

Move the ! out of the test [ if you need sh

if ! [ "$a" ]; then
Derek Schrock
  • 346
  • 1
  • 7