2

I'm trying to use environmental variables offered by OpenVPN inline.

This works just fine:

OpenVPN client config:

[...]
up /tmp/script.sh
[...]

/tmp/script.sh:

#!/bin/bash
echo $ifconfig_remote

However, if I try to do that inline, in the configuration file it doesn't work.

OpenVPN client config:

[...]
up '/bin/echo $ifconfig_remote'
[...]

It literally prints $ifconfig_remote. I've also tried to enclose it in ${ifconfig_remote} or back-ticks.

Is there a way to access/print environmental variables, without the use of external scripts?

  • Are you using this to log clients connecting and disconnecting? – callisto May 24 at 9:29
  • @callisto i honestly don't remember anymore – SaAtomic May 27 at 5:15
1

This sounds like OpenVPN directly exec()s the given command, rather than passing it to the shell. The result is that you don't get shell interpolation, which in your case means your variables are used literally.

If you don't want to use a script, try explicitly calling the shell:

up '/bin/sh -c "echo $ifconfig_remote"'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.