How to use environment variable in UNIX & windows action script

I am getting fail in the second line of concatenation. Looks, $EAMROOT is not able to pass the value. How to use environment variable inside the action script ?

UNIX one:

delete __appendfile
appendfile { concatenation “%0D%0A” of (if it starts with “PANACES_SITE_CONTROLLER_ADDRESS=” then “#” & it else if it starts with “PANACES_SITE_CONTROLLER_ADDRESS” then “#” & it else it) of lines of file "$EAMSROOT/installconfig/PanacesAgentGeneric.cfg" }
appendfile PANACES_SITE_CONTROLLER_ADDRESS={parameter “sitecontrolleraddress”}
if { not exists file “$EAMSROOT/installconfig/PanacesAgentGeneric.cfg.backup”}
copy “$EAMSROOT/installconfig/PanacesAgentGeneric.cfg” "$EAMSROOT/installconfig/PanacesAgentGeneric.cfg.backup"
endif
delete "$EAMSROOT/installconfig/PanacesAgentGeneric.cfg"
move __appendfile “$EAMSROOT/installconfig/PanacesAgentGeneric.cfg”

Windows one :

delete __appendfile
appendfile { concatenation “%0D%0A” of (if it starts with “PANACES_SITE_CONTROLLER_ADDRESS=” then “#” & it else if it starts with “PANACES_SITE_CONTROLLER_ADDRESS” then “#” & it else it) of lines of file “$EAMSROOT\installconfig\PanacesAgentGeneric.cfg” }
appendfile PANACES_SITE_CONTROLLER_ADDRESS={parameter “sitecontrolleraddress”}
if { not exists file “$EAMSROOT\installconfig\PanacesAgentGeneric.cfg.backup”}
copy “$EAMSROOT\installconfig\PanacesAgentGeneric.cfg” "$EAMSROOT\installconfig\PanacesAgentGeneric.cfg.backup"
endif
delete "$EAMSROOT\installconfig\PanacesAgentGeneric.cfg"
move __appendfile “$EAMSROOT\installconfig\PanacesAgentGeneric.cfg”

You can’t use $EAMSROOT in a path of relevance, BigFix doesn’t recognize the notation. If this is a system variable then you need to retrieve it’s value…

appendfile { concatenation “%0D%0A” of (if it starts with “PANACES_SITE_CONTROLLER_ADDRESS=” then “#” & it else if it starts with “PANACES_SITE_CONTROLLER_ADDRESS” then “#” & it else it) of lines of file ((value of variable "EAMSROOT" of environment) & “\installconfig\PanacesAgentGeneric.cfg”) }
if { not exists file ((value of variable "EAMSROOT" of environment) & “\installconfig\PanacesAgentGeneric.cfg”)}
copy "((value of variable "EAMSROOT" of environment) & “\installconfig\PanacesAgentGeneric.cfg”)" "((value of variable "EAMSROOT" of environment) & “\installconfig\PanacesAgentGeneric.cfg.backup”)"
endif
delete "((value of variable "EAMSROOT" of environment) & “\installconfig\PanacesAgentGeneric.cfg”)"
move __appendfile “((value of variable "EAMSROOT" of environment) & “\installconfig\PanacesAgentGeneric.cfg”)”

I have targeted Linux machine today and the action is failing.

Whereas QNA passed .

I am not sure where exactly the problem . Kindly suggest me .

@goperiya1 It looks like you have some smart quotes in the ‘appendfile’ lines – that happens a lot with forum copying/pasting. Try changing them to plain ASCII quotes like you’re using in the ‘parameter’ lines.

Agree the “smart quotes” are definitely a problem…also consider that the environment variables of the running BESClient may differ from the environment of your QNA session, as BESClient is running without a login shell, and hasn’t executed environment entries from .login, .profile, .bashrc, etc.

You may want to create an action to just build an appendfile of the current environment variables, you may need to refactor your approach based on where these variables are defined and whether they are available to your client.

My instincts say the client’s limited execution context doesn’t include environment variables. To take advantage of them you’d have to punt into a script executing within a client-OS-native context.

Tried . Same error. Environment variable also works fine. Let me assign one parameter variable to that value and will try to pass inside the script .

I have tried to use parameter to set the variable . However that also failing.

  1. parameter “env”="{pathname of folder (value of variable “EAMSROOT” of environment)}"

Second one also failed

parameter “env”="{(value of variable “EAMSROOT” of environment)}"

I thought to pass the variable value inside the script like below example . However unable to set the variable also

delete “”{parameter “env”} & “\installconfig\PanacesAgentGeneric.cfg”)"

Hi Jason,

I am not getting exactly what I need to do. Kindly help me.

I think those environment variables may not be defined in the BESClient environment. As a test run an action to display the variables -

Wait /bin/sh -c 'set > /tmp/variables.txt'

Then check the output file to see what environment variables are set.

As the client is not an interactive user environment, environment variables are limited. I got this just now via the Fixlet Debugger’s remote query against a CentOS system:

Q: variables of environment
A: BESClientActionMastheadPath = /etc/opt/BESClient/actionsite.afxm
A: DISPLAY = :0
A: LANG = en_US.UTF-8
A: PATH = /sbin:/usr/sbin:/bin:/usr/bin
A: PWD = /
A: SHLVL = 2
A: SYSTEMCTL_SKIP_REDIRECT = 1
A: XAUTHORITY = /root/.Xauthority
A: _ = /opt/BESClient/bin/BESClient
T: 6.000 ms

If you do the same thing in a root shell with the local qna, you will likely get a MUCH longer list of environment variables.

It’s likely that the variable you need is only be available in an interactive shell – e.g. something invoked via sh -i or sudo -l. (Note also that interactive shells are not the same as login shells.)

You could also try launching /bin/sh as a login shell

wait /bin/sh --login -c "set > /tmp/variables.txt"

and see whether that displays the environment variable you’re trying to use. You still wouldn’t be able to pull it in Relevance (the value is different because BESClient is not running in a Login Shell), but you could reference the $variable value directly in the shell script you generate.