Background: I'm configuring Transmission (v2.93) and OpenVPN (v2.4.6) in a jail (a FreeNAS 11.1 plugin jail) and want to add an --up
script to OpenVPN which will request Transmission to change its listening port (using transmission-remote
program).
My openvpn.conf
contains the following (among others):
verb 4
script-security 2
up /usr/local/etc/openvpn/set_port.sh
up-restart ;only to make the up script be executed on restarts
;but disabling this changes nothing
and the set_port.sh
script contains (a minimal script that still reproduces the behavior):
#!/usr/local/bin/bash
/usr/local/bin/transmission-remote --auth rpc_user:rpc_pass -p 6666 2>&1 > output.txt
echo 'the script itself runs: '$(pwd) $(whoami) > status.txt
The script has all permissions (777) and the binary (transmission-remote
) has all the permissions. I am aware the path to binary is actually a soft link, so I replaced it with the actual path (/usr/pbi/transmission-amd64/.sbin/transmission-remote
) but the behavior I observe is the same.
Problem: when I start OpenVPN (service openvpn start
), the script itself is executed, but the actual command fails mysteriously: the port is not being assigned (verified by looking through Transmission Remote GUI and the command generates empty output.
Contents of the debug files are as follows:
output.txt
is empty (with and without stderr redirection)
status.txt
says as expected: the script itself runs: /usr/local/etc/openvpn root
.
However, when I run this script manually (./set_port.sh
), said command completes successfully: output.txt
will say localhost:9091/transmission/rpc/ responded: "success"
and the port will be changed.
What am I missing?
Similar to this question, except I am not getting any "permission denied" messages - it seems like the command is not even executed (if I echo $(<that command>) > file.txt
, I get an empty file).
This one is also somewhat related, but the OP is asking about --client-connect
and eventually solves the issue by writing full paths to the programs they want to run - this did not help in my case (but if I echo $(ls /usr/local/bin) > log.txt
, the list of binaries is correct).
Update per @roaima's request. I changed the set_port.sh
to the following:
#!/usr/local/bin/bash
exec >debug.txt 2>&1
set -x
echo script is running
/usr/pbi/transmission-amd64/.sbin/transmission-remote --auth rpc_user:rpc_pass -p 6666 2>&1 > output.txt
then rinsed and repeated. The debug.txt
file contained these lines:
+ echo script is running
script is running
+ /usr/pbi/transmission-amd64/.sbin/transmission-remote --auth rpc_user:rpc_pass -p 12345
/usr/local/etc/openvpn/test.sh: line 5: 6795 Segmentation fault /usr/pbi/transmission-amd64/.sbin/transmission-remote --auth rpc_user:rpc_pass -p 12345 2>&1 > output.txt
output.txt
file get created, or did you previously create it before the script ran? What directory is the script running from (can you use absolute paths eg/tmp/output.txt
)? What if you send stderr to the file too (/path/to/command >/tmp/output.txt 2>&1
)? – roaima Jun 2 '18 at 8:13output.txt
,status.txt
) don't exist. And every time they are created: output is empty, status correctly reporting the user isroot
and the directory called from ($(pwd)
) is exactly where theset_port.sh
is. Redirecting stderr changes nothing. I updated the original post with this information. – Przemek D Jun 2 '18 at 13:20exec >debug.txt 2>&1
andset -x
andecho script is running
. Put the contents ofdebug.txt
into your question. – roaima Jun 2 '18 at 13:25