I have a script sending email eg when client connect/disconnect but I can't have environment variable to working ($dev)/etc/openvpn/scripts/vpn-notify.sh
I'm using --interface $dev together with curl.
If I for test use printf '%s' $dev I get eg tun11 but not together with curl.
EDIT: I'm getting the local interface specified for an outgoing connection could not be used.
it's CurlError 45
it's working fine if I remove --interface $dev
+ sleep 2
+ ip link show tun11
+ /usr/bin/curl -4 -sS --interface tun11 --connect-timeout 5 --max-time 8 https://api4.ipify.org
+ endpoint_ip=
+ curlCode=28
+ '[' -z ]
+ endpoint_ip=unknown
Seems $dev working but not possible inside script use dev environment variabel gives curl error 28.
But if i use eg wgc_vpn10 it's my wireguard client that seems working fine.
Is there any limitation to use environment variable inside a script?
A general note:
You do not explicitly state that you set and check variable $dev in your script that calls curl. If you are, then it seems strange that it does not work. If you set and checked $dev outside your script then you need to make sure the variable is available to your script and that it is not re-used and set to something else, especially if it is run by some other process than the one setting the variable.
Within a script you can set and use variables directly.
If you call (run) a script that starts a new shell then you need to share variables with the new shell to be seen inside the new shell process. Either pass the value as a command line argument or export the variable in the parent shell for it to be inherited by the new shell. There may be other options.
No as it called from vpn client and pased $dev parameter on route-up and down
option route_up '/etc/openvpn/scripts/vpn-notify.sh'
option down '/etc/openvpn/scripts/vpn-notify.sh'
my config are here: /etc/config/openvpn/
config openvpn 'Sthlmovpn'
option client '1'
option dev 'tun11'
option proto 'udp'
option nobind '1'
option persist_tun '1'
option reneg_sec '3600'
option verb '3'
option mute_replay_warnings '1'
option replay_window '256'
option auth_nocache '1'
option cipher 'AES-256-GCM'
option ca '/etc/openvpn/sthlmovpn/ca.crt'
option tls_crypt '/etc/openvpn/sthlmovpn/tlsauth.key'
option auth_user_pass '/etc/openvpn/sthlmovpn/user.pass'
option remote_cert_tls 'server'
option log '/var/log/openvpn-client2.log'
option script_security '2'
list pull_filter 'ignore "redirect-gateway"'
list pull_filter 'ignore "redirect-gateway ipv6"'
list pull_filter 'ignore "sndbuf"'
list pull_filter 'ignore "rcvbuf"'
list pull_filter 'ignore "socket-flags TCP_NODELAY"'
list pull_filter 'ignore "tun-mtu 1500"'
list data_ciphers 'AES-128-GCM'
list data_ciphers 'AES-256-GCM'
list data_ciphers 'CHACHA20-POLY1305'
option remote_random '1'
option resolv_retry 'infinite'
option server_poll_timeout '20'
option connect_retry '5'
option connect_retry_max '3'
list remote '169.150.208.246 51820'
list remote '169.150.208.158 1194'
list remote '149.50.216.205 4569'
list remote '169.150.208.247 1194'
list remote '169.150.208.187 1194'
list remote '169.150.208.187 4569'
list remote '169.150.208.247 5060'
list remote '62.93.166.123 80'
list remote '169.150.208.187 5060'
list remote '169.150.208.187 80'
list remote '169.150.208.187 51820'
list remote '169.150.208.158 80'
list remote '62.93.166.121 1194'
list remote '62.93.166.123 4569'
list remote '62.93.166.123 5060'
list remote '169.150.208.158 51820'
list remote '169.150.208.187 5060'
list remote '62.93.166.123 4569'
list remote '149.50.216.205 51820'
list remote '169.150.208.187 1194'
list remote '169.150.208.246 1194'
list remote '169.150.208.245 1194'
list remote '169.150.208.247 80'
list remote '169.150.208.216 1194'
list remote '62.93.166.123 80'
list remote '62.93.166.123 5060'
list remote '169.150.208.216 5060'
list remote '62.93.166.121 80'
list remote '169.150.208.247 4569'
list remote '169.150.208.245 4569'
list remote '169.150.208.158 5060'
list remote '169.150.208.247 51820'
list remote '169.150.208.216 4569'
list remote '62.93.166.123 1194'
list remote '62.93.166.121 4569'
list remote '149.50.216.205 5060'
list remote '169.150.208.187 80'
list remote '169.150.208.187 4569'
list remote '149.50.216.205 1194'
list remote '149.50.216.205 80'
list remote '169.150.208.216 51820'
list remote '62.93.166.123 1194'
list remote '169.150.208.245 80'
list remote '169.150.208.246 4569'
list remote '62.93.166.123 80'
list remote '169.150.208.158 4569'
list remote '62.93.166.123 1194'
list remote '169.150.208.246 80'
list remote '169.150.208.216 80'
list remote '62.93.166.123 4569'
list remote '62.93.166.121 51820'
list remote '169.150.208.245 5060'
list remote '62.93.166.123 5060'
list remote '62.93.166.123 51820'
list remote '62.93.166.123 51820'
list remote '169.150.208.245 51820'
list remote '169.150.208.246 5060'
list remote '169.150.208.187 51820'
list remote '62.93.166.121 5060'
list remote '62.93.166.123 51820'
option route_up '/etc/openvpn/scripts/vpn-notify.sh'
option down '/etc/openvpn/scripts/vpn-notify.sh'
option enabled '1'
I do not think you can do that from a route-up script.
The curl command will time out as the tunnel is not fully up just use 2>&1 instead of 2>/dev/null and ENDPOINT_IP will show the resulting error
Place the curl command in a separate script and call it asynchronously (use &) and start the script with either sleep 10 or better add retry to the curl command e.g.: