What's new
SNBForums

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Why does this code only work sometimes?

Hothersale

Occasional Visitor
I have a little script that makes a call to an API to find out which port has been assigned to me by my VPN provider.

The script works perfectly when I run it manually or when it is run as a cron job. A certain part of the script fails, however, when the script is called from the openvpn-event user script. This is the line of code:

Code:
curl -k -d "user=$PIANAME&pass=$PIAPASS&client_id=$CLIENTID&local_ip=$LOCALIP" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment 2>/dev/null|grep -oE "[0-9]+" > /tmp/vpn_port

The file "vpn_port" gets created, but it is empty instead of containing the port number. The curl command is failing somehow. All the variables are present and accounted for... I'm stumped. It's like openvpn-event doesn't have permission to execute the curl command or something.

Any of you bearded gurus have an idea what might be wrong? ;)

Cheers,
Chris
 
Try redirecting all of the output to a file so that you can see any error messages.
Code:
curl -k -d "user=$PIANAME&pass=$PIAPASS&client_id=$CLIENTID&local_ip=$LOCALIP" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment >/tmp/vpn_port.debug 2>&1
 
The only thing is different when script starts from cron, daemon or shell is environment. Please, put full path to curl into script and problem (in most cases) will be solved.
 
Thank you for your responses.

The debug file shows transfer stats such as this:

Code:
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0^M100   107    0    14  100    93     21    1$

Does this help?

Putting the full path to curl (/opt/bin/curl) doesn't make any difference, unfortunately.
 
Does this help?

Not much. Without seeing the whole script as well as the full output it's going to be almost impossible to diagnose.

That said, try the following and show us the contents of both output files when the script fails:

Code:
curl -k -d "user=$PIANAME&pass=$PIAPASS&client_id=$CLIENTID&local_ip=$LOCALIP" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment >/tmp/vpn_port 2>/tmp/vpn_port.err
 
Last edited:

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top