Elevation privilege script

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
Hi,

Trying to create a script for my Elevation privilege on my engine, but i'm stuck on how to create a script with multilines.

How to indecate new line when for example you set the contect of privilege script at the cli

eg. LandsharkEngine host privilegeElevation profileScript 'msa_commande' update *> set contents=


Regards,

Mouhssine
Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,782 Points 4k badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Edward de los Santos

Edward de los Santos, Employee

  • 110 Points 100 badge 2x thumb
Official Response
Hello Mouhssine,

The multiline have some challenges in CLI. You can achieve this by writing a bash shell function to extract the file contents for elevation profile script (e.g. dlpx_pfexec, dlpx_mkdir...)

Code snippet:
extract_contents()
{
   PROFILE_NAME="${1}"
   SCRIPT_FILE="${2}"
   CONTENTS=""
   row=""

   PFEXEC_FILE="${BASEDIR}/${PROFILE_NAME}/${SCRIPT_FILE}"

   if [ ! -f ${PFEXEC_FILE} ]; then
      echo "Error: Can't read file ${PFEXEC_FILE}"
      exit 1
   fi
   IFS=''
   while read line  || [ -n "${line}" ]
   do
      row=`echo "${row}\n${line}"`
   done < ${PFEXEC_FILE}

   CONTENTS=$(echo "${row}" | sed -e 's/\"/\\\"/g' | sed -e 's/\$/'\$'/g' | sed -e 's/\t/    /g' )

}
Then pass the CONTENTS to a WebAPI call
create_profile_script()
{
   URL="${1}"
   PROFILE_REF="${2}"
   NAME="${3}"
   CONTENTS="${4}"
   echo "Creating profile script ${NAME}"
   RESULT=`curl -s -X POST -k --data @- ${URL}/resources/json/delphix/host/privilegeElevation/profileScript \
      -b ${COOKIE_FILE} -H "Content-Type: application/json" <<EOF
   {
      "type": "HostPrivilegeElevationProfileScript",
      "profile": "${PROFILE_REF}",
      "name": "${NAME}",
      "contents": "${CONTENTS}"
   }
EOF`

Here are the additional reference to Elevation Profile
Hope this helps.

- Edward