Ampersand "&" in the API action

I have this statement in the action API where & is tripping. If i use %26 the client said its invalid command.

\nappendfile chmod 644 $bftask_log $log
\nmove __appendfile /tmp/sox.sh
\nwait chmod 755 /tmp/sox.sh
\nwait /tmp/sox.sh “”"+cmd_argu+"""
\nsetting “BESClient_ArchiveManager_FileSet-{computer name & "” & (month of it as two digits & day_of_month of it as two digits & ye
ar of it as string) of current date}" = “/tmp/soxtxt” on “{now}” for client
\nsetting _BESClient_ArchiveManager_OperatingMode = 2 on “{now}” for client
\narchive now
\ndelete /tmp/sox.sh “”"

Sleeping for 30sec, to let the ACTION to spawn in bigfix:
Traceback (most recent call last):
File “sox_run_bigfix.py”, line 327, in
call_action(computer_target)
File “sox_run_bigfix.py”, line 247, in call_action
tree2 = ET.fromstring(req_bes_query_id.text)

in the client it has command failed . If I replace & with %26.

Command failed (Relevance substitution failed) setting “BESClient_ArchiveManager_FileSet-{computer name %26 "” %26 (month of it as two digits %26 day_of_month of it as two digits %26 year of it as string) of current date}" = “/tmp/soxtxt” on “{now}” for client (action:1632388)

this failed too

Command failed (Relevance substitution failed) setting “BESClient_ArchiveManager_FileSet-{computer name %26%20%22%22%20%26 (month of it as two digits %20%26%20 day_of_month of it as two digits %20%26%20 year of it as string) of current date}” = “/tmp/soxtxt” on “{now}” for client (action:1632404)

This will be a lot more about how you are sending the action via REST. The actionscript itself needs to contain the literal & character so you’ll need to determine how to encode that in your tool.

How are you posting the action? Iem.exe? Curl? Python? Powershell? Can you provide a code snippet?

Since you are posting an action, we need to examine the XML that you’re posting rather than the script you expect you’re ending up with.

Its python code…

This is what I do… apparently &amp seems worked.

copy/pastingi the xml is messing the stuff here. not sure how to avoid that.

def build_xml(computer_target):

action_script=“”“\ndelete __appendfile
\ndelete /tmp/sox.sh
\nappendfile os_name=hostname
\nappendfile short_name=echo $os_name|awk -F. ' {{print $1}'
\nappendfile dt=date +%y%m%d
\nappendfile log=/tmp/sox.txt
\nappendfile bftask_log=/tmp/bftask_sox.log
\nappendfile err1=”"
\nappendfile err2=“”
\nappendfile cmd_arg=$1
\nappendfile script_arg=“”
\nappendfile if [ -z “$cmd_arg” ]
\nappendfile then
\nappendfile echo “Usage: pass argument 0,1=-f and 2=‘-z -f’ "
\nappendfile exit 1
\nappendfile fi
\nappendfile if [ “$cmd_arg” = “0” ]
\nappendfile then
\nappendfile script_arg=”"
\nappendfile fi
\nappendfile if [ “$cmd_arg” = “1” ]
\nappendfile then
\nappendfile script_arg=“-f”
\nappendfile fi
\nappendfile if [ “$cmd_arg” = “2” ]
\nappendfile then
\nappendfile script_arg=“-z -f”
\nappendfile fi
\nappendfile run_exp()
\nappendfile {{
\nappendfile expect_bin=which expect
\nappendfile if [ ! -z “$expect_bin” ]
\nappendfile then
\nappendfile echo “spawn /usr/local/secbase/sox_verification.ksh $script_arg " > /tmp/sox.exp
\nappendfile echo “sleep 10” >> /tmp/sox.exp
\nappendfile echo expect “Do you want to continue (y/n)?”>> /tmp/sox.exp
\nappendfile echo send “y\r” >> /tmp/sox.exp
\nappendfile echo expect eof >> /tmp/sox.exp
\nappendfile $expect_bin -f /tmp/sox.exp > $log
\nappendfile else
\nappendfile err1=“expect binnotfound_after_yum”
\nappendfile fi
\nappendfile }
\nappendfile if [ -f /usr/local/secbase/sox_verification.ksh ]
\nappendfile then
\nappendfile k=which expect
\nappendfile if [ ! -z “$k” ]
\nappendfile then
\nappendfile if [ “$cmd_arg” = “0” ]
\nappendfile then
\nappendfile /usr/local/secbase/sox_verification.ksh $script_arg > $log
\nappendfile else
\nappendfile run_exp
\nappendfile fi
\nappendfile else
\nappendfile timeout 20s yum install -y expect.x86_64
\nappendfile if [ “$cmd_arg” = “0” ]
\nappendfile then
\nappendfile /usr/local/secbase/sox_verification.ksh $script_arg > $log
\nappendfile else
\nappendfile run_exp
\nappendfile fi
\nappendfile fi
\nappendfile else
\nappendfile err2=“sox_verification.ksh notFound”
\nappendfile fi
\nappendfile if [ -f “$log” ]
\nappendfile then
\nappendfile echo “soxlog $log Found,$err1,$err2” > $bftask_log
\nappendfile else
\nappendfile echo “soxlog $log NotFound,$err1,$err2” > $bftask_log
\nappendfile fi
\nappendfile chmod 644 $bftask_log $log
\nmove __appendfile /tmp/sox.sh
\nwait chmod 755 /tmp/sox.sh
\nwait /tmp/sox.sh “””+cmd_argu+“”"
\nsetting “BESClient_ArchiveManager_FileSet-{computer name &"”& (month of it as two digits & day_of_month of it as two digits & year of it as string) of current date}" = “/tmp/soxtxt” on “{now}” for client
\nsetting _BESClient_ArchiveManager_OperatingMode = 2 on “{now}” for client
\narchive now
\ndelete /tmp/sox.sh “”"
xml_query='<?xml version="1.0" encoding="utf-8"?>\

… here is the modified code with “amp” instead “&”

That xml looks all kinds of corrupt to me. I don’t think that in Python your combination of three-quotes for a multiline string, and \n for newline is doing what you expect.

Before you try to post your action, just build the xml file and save it, then read it in an editor to see how it looks.

When posting xml or any code to the forum, highlight it and select the “Code” tag that looks like </> just above the editor window.

I strongly suggest you use Python’s XML libraries (I use ElementTree myself, but there are several) rather than just building a big string. That way you can do things like set a node value to <[CDATA[ my long relevance or actionscript ]]> and let the XML library to all of the translations and encodings for you.

nah its not corrupt. I have being using the similar syntax in number of python codes and it works fine. The issue is resolved using the amp instead of &.

Ok, glad it’s working for you. It’s hard for me to tell which of your screenshots are Python source, and which are the resulting XML document (reading on a phone here)

(I still recommend using ElementTree for XML. Once you start treating XML as the Object it’s meant to be, rather than the long string that it isn’t, you’ll never go back)

nah I don’t use the element trees. I have used that before. i would rather pick the tag which i am looking for and get it processed. Some of the code i do have element tree when i first start poking the api in python.
script has lots of quotes in it so the only way to avoid the quotes error is to use tripple quote around the whole string… I have tried it multiple way but triple quotes works fine.
XML always get twitchy with having & in the strings, and passing xml url to the API/POST.

I tried not to use the console as much as possible that;s why i do most of the action via script/API. it can be done pretty easy via console just copy/paste the shell script or prefetch it.

thanks for checking though as always.