Script to port forward port to Transmission plugin (in jail)

Status
Not open for further replies.

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi all,

I've followed this guide to setup OpenVPN and IPFW.

My Transmission jail is up and running. My VPN (PIA) is configured and works with OpenVPN. My firewall is configured with ipfw and works (the connection is stopped if the VPN stops). My only concern now is to port forward a port to Transmission. I'm using FreeNAS 9.10, PIA for VPN and IPFW.

I tried to use this script to port forward a port to Transmission (as this script generates the same port each time it is executed, according to the author) . However, I get an error (command not found) when I try to execute the script. I've been reading a lot, specially this thread, and I followd Glorious1 advice to install bash, as you can see per code, but it's already installed. So, I don't know what to try now to get the script working. Could you please help me with this issue?

Code:
root@transmission_1:/ # cd /usr/local/etc/openvpn							 
root@transmission_1:/usr/local/etc/openvpn # ls								
4b05e93c63684ea1a95518fcfbd8a6a04461b1d5										
PIA																			
ca.rsa.2048.crt																
crl.rsa.2048.pem																
openvpn.conf																	
openvpn.zip																	
password.txt																	
port_forward.sh																
port_forward.sh.1															 
root@transmission_1:/usr/local/etc/openvpn # pkg install bash				 
Updating FreeBSD repository catalogue...										
FreeBSD repository is up-to-date.											 
All repositories are up-to-date.												
Checking integrity... done (0 conflicting)									
The most recent version of packages are already installed					 
root@transmission_1:/usr/local/etc/openvpn # ./port_forward.sh testuname testpas
sword																		 
./port_forward.sh: Command not found.										 
root@transmission_1:/usr/local/etc/openvpn #


Thanks a lot!
 
Last edited:

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi everyone,

Ok, so I managed to get pass this "command not found" error. However, now I'm stuck with an other error. I get "missing name for redirect" whenever I execute the bash script.

Code:
root@transmission_1:/usr/local/etc/openvpn # bash ./port_forward.sh <username> <
password>																	 
Missing name for redirect.													
root@transmission_1:/usr/local/etc/openvpn #


I saw on a few forums and posts on internet that this could be caused because I don't actually run bash. However, I execute my script with "bash" before it's name, so I fugure I should be ok, no? Also, if it can be of any use, I log in my jail using the command "jexec transmission-1 tcsh".

I tried to see if loggin in my jail with the command "jexec transmission-1 bash" would work, but then I got different errors (syntax error and bad interpreter):

Code:
[root@transmission_1 /usr/local/etc/openvpn]# ./port_forward.sh <username> <pass
word>																		   
bash: syntax error near unexpected token `<'									
[root@transmission_1 /usr/local/etc/openvpn]# ./port_forward.sh username passwor
d																			   
bash: ./port_forward.sh: /bin/bash: bad interpreter: No such file or directory 
[root@transmission_1 /usr/local/etc/openvpn]#								   
Coller


I don't understand why it's doing this and how I can make it work. Do you have any suggestions?

Thank you very much!

Blaccko
 
Last edited:

colmconn

Contributor
Joined
Jul 28, 2015
Messages
174
You are supposed to replace <username> with the username and likewise for <password>.
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi colmconn,

Thanks for your answer. Yes, that's what I did. I just didn't want to post my username and password, so that's why I replaced them with generics! ; ) I should have mentionned though. But anyway, I had the same result when I used my username and password. Any other thoughts?

Thanks again!

Blaccko
 
D

dlavigne

Guest
What path is given if you type which bash in the jail?
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
Check your tunnel adapter syntax with ifconfig:

Code:
root@transmission_1:/ # ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
	options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
	inet6 ::1 prefixlen 128
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
	inet 127.0.0.1 netmask 0xff000000
	nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
epair1b: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=8<VLAN_MTU>
	ether 00:aa:bb:00:77:1b
	inet 10.25.10.229 netmask 0xffffff00 broadcast 10.25.10.255
	nd6 options=9<PERFORMNUD,IFDISABLED>
	media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)
	status: active
tun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500
	options=80000<LINKSTATE>
	inet 10.11.11.16 --> 10.93.101.56 netmask 0xffffffff
	nd6 options=1<PERFORMNUD>
	Opened by PID 10759
root@transmission_1:/ #


In my case, my tunnel adapter is tun1, not tun0 as is the default in the script. So check that and change the shell script to use the proper tunnel adapter name.

I have been way to lazy to figure out how to detect what the tunnel adapter's name is automatically but if someone knows how to do that, please share :)

Cheers,
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi everyone,

dlavigne, the command "which bash", when I type it after login in with the command "jexec transmission_1 tcsh" gives me the following.

Code:
[root@freenas ~]# jexec transmission_1 tcsh									 
root@transmission_1:/ # which bash											 
/usr/local/bin/bash															 
root@transmission_1:/ #


When I do the same thing after login in with the command "jexec transmission_1 bash", I get the following.

Code:
[root@freenas ~]# jexec transmission_1 bash									 
[root@transmission_1 /]# which bash											 
/usr/local/bin/bash															 
[root@transmission_1 /]#		 


Which methond (tcsh or bash) should I use to login to my Transmission jail? Also, should I adapt something regardint the results I got for the command "which bash"?

Scharbag, the tunnel syntax for my is "tun0". So, that matches the script.

Code:
[root@freenas ~]# jexec transmission_1 tcsh									 
root@transmission_1:/ # ifconfig												
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384			   
		options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>				   
		inet6 ::1 prefixlen 128												 
		inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1							 
		inet 127.0.0.1 netmask 0xff000000									   
		nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>							   
epair2b: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500   
		options=8<VLAN_MTU>													 
		ether 02:ff:70:00:06:0b												 
		inet 192.168.6.112 netmask 0xffffff00 broadcast 192.168.6.255		   
		nd6 options=9<PERFORMNUD,IFDISABLED>									
		media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)					 
		status: active														 
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500			
		options=80000<LINKSTATE>												
		inet 10.91.10.6 --> 10.91.10.5 netmask 0xffffffff					   
		nd6 options=1<PERFORMNUD>											   
		Opened by PID 33256													 
root@transmission_1:/ #


So, I don't think there something wrong with this.

Thank you both of you for your answers!

Blaccko
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
Code:
#! /usr/local/bin/bash
#
# Enable port forwarding
#
# Requirements:
#   your Private Internet Access user and password as arguments
#
# Usage:
#  ./port_forward.sh <user> <password>

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"
echo "Transmission Port Forward $(date +%Y-%m-%d-%H:%M:%S)"

error( )
{
  echo "$@" 1>&2
  exit 1
}

error_and_usage( )
{
  echo "$@" 1>&2
  usage_and_exit 1
}

usage( )
{
  echo "Usage: `dirname $0`/$PROGRAM <user> <password>"
}

usage_and_exit( )
{
  usage
  exit $1
}

version( )
{
  echo "$PROGRAM version $VERSION"
}


port_forward_assignment( )
{
  echo 'Loading port forward assignment information..'
  if [ "$(uname)" == "Linux" ]; then
	local_ip=`ifconfig tun0|grep -oE "inet addr: *10\.[0-9]+\.[0-9]+\.[0-9]+"|tr -d "a-z :"|tee /tmp/vpn_ip`
	client_id=`head -n 100 /dev/urandom | md5sum | tr -d " -"`
  fi
  if [ "$(uname)" == "FreeBSD" ]; then
	local_ip=`ifconfig tun1 | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`
	client_id=`head -n 100 /dev/urandom | md5 -r | tr -d " -"`
  fi
  json=`wget --no-check-certificate -q --post-data="user=$USER&pass=$PASSWORD&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
  echo $json
  PORTNUM=`echo $json | grep -oE "[0-9]+"`
}

EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0
USER=$1
PASSWORD=$2

while test $# -lt 2
do
  case $1 in
  --usage | --help | -h )
	usage_and_exit 0
	;;
  --version | -v )
	version
	exit 0
	;;
  *)
	error_and_usage "Unrecognized option: $1"
	;;
  esac
  shift
done

port_forward_assignment

transmission-remote -p $PORTNUM

exit 0


Above is the script that I use. I notice that your bash location in the beginning of the script you link to is /bin/bash whereas bash is located in /usr/local/bin/bash within your jail, as like in mine.

Might that be the issue?

Cheers,
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi,

Thanks for your help. I tried editing the script to put "#!/usr/local/bin/bash/" in the first line instead of "#!/bin/bash". However, it didn't help. : (

Here is the output, after having edited the script as per above:
Code:
[root@freenas ~]# jexec transmission_1 tcsh									 
root@transmission_1:/ # cd /usr/local/etc/openvpn							   
root@transmission_1:/usr/local/etc/openvpn # ./port_fowad.sh <myusername> <mypasw
ord>																			
Missing name for redirect.
root@transmission_1:/usr/local/etc/openvpn # bash port_forward.sh <myusername> <
mypassword>																	 
Missing name for redirect.													 


I also tried the same procedure in a jail executed with "jexec transmission_1 bash" instead of "jexec transmission_1 tcsh", but the result was the same error that I had before in jail started with bash:

Code:
[root@transmission_1 /usr/local/etc/openvpn]# ./port_forward.sh <myusername> <mypass
word>																		   
bash: syntax error near unexpected token `<'									
[root@transmission_1 /usr/local/etc/openvpn]# ./port_forward.sh myusername mypasswor
d																			   
bash: ./port_forward.sh: /bin/bash: bad interpreter: No such file or directory


So, I still don't know what to do regarding this script and how to port forward a port to my jail using OpenVPN. I'm still open to all your help and your suggestions folks! ; )

Thanks in a lot!

Blaccko
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi everyone,

I tried to restart everything (removing the jail and doing the setup again), but it still not working. The result is that I can't download using PIA. That's bothering, because that's why I bought a PIA access in the first place...!

So, I'm still open for any suggestions you may have to help me resolve my problem of port forward with PIA in a jail.

Thanks in advance,

Blaccko
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
So strange. I will create a new transmission jail to see if I run into the same issue. I will let you know what I figure.
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
So, I created a second Transmission plugin jail by installing transmission again.

I logged into the jail using jexec 7 csh. I then installed openvpn in the following way (notice that I did not install the latest bash at this time and I forgot to check if bash is installed as default):

Code:
pkg install -y openvpn wget nano

mkdir -p /usr/local/etc/openvpn
mkdir -p /usr/local/etc/pia_openvpn


I copied my openvpn, ipfw and port-forward files from my first transmission jail into the pia_openvpn folder. I assume that you have both openvpn and ipfw running properly. These are the instructions that I use.

I then edited \etc\rc.conf to have:

Code:
portmap_enable="NO"
sshd_enable="NO"
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
hostname="transmission_2"
devfs_enable="YES"
devfs_system_ruleset="devfsrules_common"
inet6_enable="YES"
ip6addrctl_enable="YES"
transmission_conf_dir="/var/db/transmission"
transmission_download_dir=""
openvpn_enable="YES"
openvpn_if="tun"
openvpn_configfile="/usr/local/etc/pia_openvpn/pia_vpn.conf"
firewall_enable="YES"
firewall_type="/usr/local/etc/pia_openvpn/ipfw.rules"
transmission_enable="YES"


Given my tunnel adapter is now tun2, I edited the port forward.sh file accordingly:

Code:
#! /usr/local/bin/bash
#
# Enable port forwarding
#
# Requirements:
#   your Private Internet Access user and password as arguments
#
# Usage:
#  ./port_forward.sh <user> <password>

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"
echo "Transmission Port Forward $(date +%Y-%m-%d-%H:%M:%S)"

error( )
{
  echo "$@" 1>&2
  exit 1
}

error_and_usage( )
{
  echo "$@" 1>&2
  usage_and_exit 1
}

usage( )
{
  echo "Usage: `dirname $0`/$PROGRAM <user> <password>"
}

usage_and_exit( )
{
  usage
  exit $1
}

version( )
{
  echo "$PROGRAM version $VERSION"
}


port_forward_assignment( )
{
  echo 'Loading port forward assignment information..'
  if [ "$(uname)" == "Linux" ]; then
	local_ip=`ifconfig tun0|grep -oE "inet addr: *10\.[0-9]+\.[0-9]+\.[0-9]+"|tr -d "a-z :"|tee /tmp/vpn_ip`
	client_id=`head -n 100 /dev/urandom | md5sum | tr -d " -"`
  fi
  if [ "$(uname)" == "FreeBSD" ]; then
	local_ip=`ifconfig tun2 | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`
	client_id=`head -n 100 /dev/urandom | md5 -r | tr -d " -"`
  fi
  json=`wget --no-check-certificate -q --post-data="user=$USER&pass=$PASSWORD&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
  echo $json
  PORTNUM=`echo $json | grep -oE "[0-9]+"`
}

EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0
USER=$1
PASSWORD=$2

while test $# -lt 2
do
  case $1 in
  --usage | --help | -h )
	usage_and_exit 0
	;;
  --version | -v )
	version
	exit 0
	;;
  *)
	error_and_usage "Unrecognized option: $1"
	;;
  esac
  shift
done

port_forward_assignment

transmission-remote -p $PORTNUM

exit 0


Even without bash installed (or upgraded), the port forward succeeds (of course you need to use your user and password:) ):

Code:
root@transmission_2:/usr/local/etc/pia_openvpn # sh portforward.sh 'user' 'password'
Transmission Port Forward 2016-12-08-15:31:16
Loading port forward assignment information..
{"port":25896}
localhost:9091/transmission/rpc/ responded: "success"


I then tried using the tsch shell and it also succeeded. So, for giggles, I installed the latest bash and it still worked fine when using the bash/csh/tcsh shells.

Questions:
  • your transmission jail has a full network stack (VIMAGE is enabled)?
  • do you have wget installed in the transmission jail?
  • have you confirmed that openvpn is running properly?
    drill +short myip.opendns.com @resolver1.opendns.com
  • if you are using ipfw, have you confirmed that it is working properly with ipfw show
Please let us know as this is a bit of a noodle scratcher!

Cheers,
 

Blaccko

Dabbler
Joined
Apr 10, 2015
Messages
14
Hi Scharbag,

I really appreciate you taking the time to help me! Thanks for that.

To answer your questions, I'll have to check the jail's properties when I get home tonight, as I'm not sure if VIMAGE is enabled for my jail.

Also, I'm pretty sure I have wget installed in my jail, but I'll confirm that also tonight.

I didn't use the code line you provided to check if OpenVPN is running properly, but I checked with the torrent file (Torrent IP checker for TorGuard) to see if the IP of my jail was different that its original when OpenVPN was running and it was, so I assume OpenPVN is running properly. Nevertheless, I'll run the command you mentionned tonight when I get to my NAS.

Finally, I used the method mentionned here to confirm that IPFW is working properly. However, I'll also run the command ipfw show tonight.

In short, I'll get back to you later when I get the chance to test all that on my NAS, but thanks for taking the time to help me out with this issue!

Have a good day,

Blaccko
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
Here's a cronable port forwarding script I made for myself:
https://gist.github.com/spede/1be831352fbfdf3973ad477778d38afe

It should mostly work. :confused:

It also attempts to restart openvpn because my internet is unstable at times. Some may want to remove that part.
The script will not work for me. I get the following error:
Code:
oot@transmission_1:/usr/local/etc/pia_openvpn # sh portforward2.sh
Connection to google.com 80 port [tcp/http] succeeded!
VPN connection up.
portforward2.sh: [[: not found
portforward2.sh: [[: not found
Error: transmission said: Port is open: Yes


I copied and pasted the script into the portforward2.sh file and edited the tun adapter to be tun1 as well as inserted my credentials for PIA.

Not sure what is going down. Seems that the error is coming from the section of code that checks to see if the port is forwarded.

Cheers,
 
Last edited:

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
OK,

I smashed the 2 different methods into a single script that is cron friendly and works on my system:

Code:
#! /usr/local/bin/bash
#
# Enable port forwarding for transmission specifically in FreeBSD.
#
# Requirements:
#   this can be executed from cron or from the shell with no arguments.
#   ensure that your PIA credentials are entered in this script.
#
# Packages needed:
#   pkg install -y sudo nano wget openvpn bash
#
# Usage:
#  ./port_forward.sh or sh port_forward.sh or call from cron

PIA_USER='PIA_USER_HERE'
PIA_PASS='PIA_PASSWORD_HERE'

# Export path for when you use this in cron
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

# echo date/time for logging
echo "Transmission Port Forward $(date +%Y-%m-%d-%H:%M:%S)"

# test to see if the port is already forwarded and if so, exit script
is_port_forwarded( )
{
# -pt tests for open port.
	json=$(transmission-remote -pt)
	if [ "$json" == "Port is open: No" ]; then
		echo "Closed port detected"
			get_new_port
	elif [ "$json" == "Port is open: Yes" ]; then
		echo "Open port detected"
		exit 1
	else
		echo "Error: transmission said: $json"
		exit 0
	fi
}

# if port is not forwarded, get a new port for transmission
get_new_port( )
{
	echo 'Loading port forward assignment information..'
   # dynamically figure out the tunnel adapter name
	tunnel_adapter=`ifconfig | grep "tun" | cut -d ":" -f1`
	local_ip=`ifconfig $tunnel_adapter | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`
	json=`wget --no-check-certificate -q --post-data="user=$PIA_USER&pass=$PIA_PASS&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
	PORTNUM=`echo $json | grep -oE "[0-9]+"`
	# test to make sure that the port is actually a number
	if echo "$PORTNUM" | grep -qE ^\-?[0-9]+$; then
		   # it IS numeric
		echo "New port: $PORTNUM"
		transmission-remote -p $PORTNUM
	else
		# it is NOT numeric.
		echo "Garbled data: $PORTNUM"
		exit 0
	fi
}

re_check_connectivity( )

{

		if sudo -u transmission nc -zw 1 google.com 80; then
			echo "VPN connection restored."
			sleep 10 #this delay seems to be needed for the script to work properly
			echo "Attempting to map port:"
			is_port_forwarded
	else
			echo "Unable to restore VPN connection. Subscription expired? Exiting."
			 exit 0
	fi
}

check_for_connectivity( )
{
	if sudo -u transmission nc -zw 1 google.com 80; then
				echo "VPN connection up."
		is_port_forwarded
		else
				echo "VPN connection down. Restarting..."
				service openvpn restart
		sleep 5 # wait for OpenVPN to start prior to checking for connectivity
				re_check_connectivity
		fi
}

# First check for connectivity using the user that executes Transmission.  If this fails, script will try to relaunch openvpn service and re-check (5 second pause to allow OpenVPN to start)
# If re-check fails, script will exit without any other execution.
#
# Second this will check for port forward status.  If the port forward is enabled, script will exit.  If the port is not properly forwarded, the script will
# call for a new port assignment and if it is valid, will tell transmission to use the new port.

check_for_connectivity
is_port_forwarded

exit 0


Usage is now just a simple ./portforward.sh or sh portforward.sh or call directly from cron. Given that this will only change the port if it detects it to be not forwarded, I run this script every 5 mins using cron.

Code:
# +--------- Minute (0-59)					| Output Dumper: >/dev/null 2>&1
# | +------- Hour (0-23)					  | Multiple Values Use Commas: 3,12,47
# | | +----- Day Of Month (1-31)			  | Do every X intervals: */X  -> Example: */15 * * * *  Is every 15 minutes
# | | | +--- Month (1 -12)					| Aliases: @Reboot -> Run once at startup; @hourly -> 0 * * * *;
# | | | | +- Day Of Week (0-6) (Sunday = 0)   | @daily -> 0 0 * * *; @weekly -> 0 0 * * 0; @monthly ->0 0 1 * *;
# | | | | |								   | @yearly -> 0 0 1 1 *;
# * * * * * COMMAND						   |
@Reboot sleep 10 && /usr/local/etc/pia_openvpn/portforward.sh >> /var/log/pia.log 2>&1
*/5 * * * * /usr/local/etc/pia_openvpn/portforward.sh >> /var/log/pia.log 2>&1
@weekly /usr/local/etc/pia_openvpn/ubl.sh >> /var/log/blocklistupdate.log 2>&1


The ubl.sh just updates the block list once a week with:

Code:
#!/bin/sh

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

echo "Blocklist Update $(date +%Y-%m-%d-%H:%M:%S)"

transmission-remote --blocklist-update


And, after some minor swearing about the fact that ` is not ', I have figured out how to dynamically determine the tunnel adapter's name:

Code:
# dynamically figure out the tunnel adapter name
	tunnel_adapter=`ifconfig | grep "tun" | cut -d ":" -f1`
	local_ip=`ifconfig $tunnel_adapter | grep "inet " | cut -d\  -f2|tee /tmp/vpn_ip`


Cheers,

Side note: is there a way to make formatting easier in this forum's editor?
 
Last edited:

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Hi the script aboe is giving errors.

/usr/local/etc/pia_openvpn/port_forward.sh: Command not found.
root@transmission_1:/usr/local/etc/pia_openvpn # sh /usr/local/etc/pia_openvpn/port_forward.sh
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
Transmission Port Forward 2016-12-17-18:41:43
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh: {
/usr/local/etc/pia_openvpn/port_forward.sh: 32: Syntax error: "elif" unexpected (expecting "then")
root@transmission_1:/usr/local/etc/pia_openvpn # sh /usr/local/etc/pia_openvpn/port_forward.sh
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
Transmission Port Forward 2016-12-17-19:35:40
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh: {
/usr/local/etc/pia_openvpn/port_forward.sh: 32: Syntax error: "elif" unexpected (expecting "then")
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
Hi the script aboe is giving errors.

/usr/local/etc/pia_openvpn/port_forward.sh: Command not found.
root@transmission_1:/usr/local/etc/pia_openvpn # sh /usr/local/etc/pia_openvpn/port_forward.sh
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
Transmission Port Forward 2016-12-17-18:41:43
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh: {
/usr/local/etc/pia_openvpn/port_forward.sh: 32: Syntax error: "elif" unexpected (expecting "then")
root@transmission_1:/usr/local/etc/pia_openvpn # sh /usr/local/etc/pia_openvpn/port_forward.sh
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh:
Transmission Port Forward 2016-12-17-19:35:40
: not foundetc/pia_openvpn/port_forward.sh:
: not foundetc/pia_openvpn/port_forward.sh: {
/usr/local/etc/pia_openvpn/port_forward.sh: 32: Syntax error: "elif" unexpected (expecting "then")
First, you need to make the script executable to call it directly without the ./ or sh in front of it. Do this by using chmod +x <file>. If it is executable, it is pointing to a problem with BASH as that is the shell that is called in the script.

Also, what is the result of where bash? I am new at this but I think that elif may be understood in BASH but possibly not by SH, CSH etc. Try that and let me know.

Cheers,
 
Last edited:

denist

Contributor
Joined
Jan 28, 2013
Messages
188
I dont think i have bash installed. And i cant get the script to execute without the sh see below.

root@transmission_1:/usr/local/etc/pia_openvpn # chmod +x port_forward.sh
root@transmission_1:/usr/local/etc/pia_openvpn # ./ port_forward.sh
./: Permission denied.
root@transmission_1:/usr/local/etc/pia_openvpn # ./port_forward.sh
./port_forward.sh: Command not found.
root@transmission_1:/usr/local/etc/pia_openvpn # sudo ./ port_forward.sh
sudo: Command not found.
root@transmission_1:/usr/local/etc/pia_openvpn #
 
Status
Not open for further replies.
Top