Starter Shell Automation

Version 3
    Share:|

    RPM ships with a bunch of integration-based automation.  Here are a few basic actions to help fill in the content.

     

    sh_runCommand (linux/windows):

    This automation takes up to 4 lines of commands as arguments and executes them in sequence on the remote target.  Pretty basic but it avoids have to write a new automation for all of your one-liners (or nearly one liners).

     

    How it works:

         The principle is simple, take the incoming argument and put it on the command line.  There is a little trick there because bash expands the $xxx variable once and then doesn't parse it again.  This kills things like | and ;.  By wrapping it in bash -c "$xxx", its evaluated and parsed.

     

    Source(linux-bash):

    # sh_runCommand(linux)

    #

    # Executes COMMAND_TO_EXECUTE in TARGET_PATH using bash

    #

     

    ###

    #

    # COMMAND_TO_EXECUTE:

    #   name: First line of commands to execute

    #   position: A1:F1

    #   type: in-text

    #

    # COMMAND_TO_EXECUTE1:

    #   name: Second line of commands to execute

    #   position: A2:F2

    #   type: in-text

    #

    # COMMAND_TO_EXECUTE2:

    #   name: Third line of commands to execute

    #   position: A3:F3

    #   type: in-text

    #

    # COMMAND_TO_EXECUTE3:

    #   name: Fourth line of commands to execute

    #   position: A4:F4

    #   type: in-text

    #

    # TARGET_PATH:

    #   name: Target file path to append to

    #   position: A5:F5

    #   type: in-text

    #

    ###

     

    if [[ $TARGET_PATH -ne "" ]]; then

      cd $TARGET_PATH

    fi

    echo "1-Executing $COMMAND_TO_EXECUTE"

    bash -c "$COMMAND_TO_EXECUTE"

    if [[ ${#COMMAND_TO_EXECUTE1} -gt 2 ]]; then

      echo "2-Executing $COMMAND_TO_EXECUTE1"

      bash -c "$COMMAND_TO_EXECUTE1"

    fi

    if [[ ${#COMMAND_TO_EXECUTE2} -gt 2 ]]; then

      echo "3-Executing $COMMAND_TO_EXECUTE2"

      bash -c "$COMMAND_TO_EXECUTE2"

    fi

    if [[ ${#COMMAND_TO_EXECUTE3} -gt 2 ]]; then

      echo "4-Executing $COMMAND_TO_EXECUTE3"

      bash -c "$COMMAND_TO_EXECUTE3"

    fi

     

    Source (windows-powershell)

    #![.ps1]powershell.exe -ExecutionPolicy Unrestricted -File

    #

    # cmd_runCommand(windows)

    #

    # Executes COMMAND_TO_EXECUTE in TARGET_PATH using bash

    #

     

    ###

    #

    # COMMAND_TO_EXECUTE:

    #   name: First line of commands to execute

    #   position: A1:F1

    #   type: in-text

    #

    # COMMAND_TO_EXECUTE1:

    #   name: Second line of commands to execute

    #   position: A2:F2

    #   type: in-text

    #

    # COMMAND_TO_EXECUTE2:

    #   name: Third line of commands to execute

    #   position: A3:F3

    #   type: in-text

    #

    # COMMAND_TO_EXECUTE3:

    #   name: Fourth line of commands to execute

    #   position: A4:F4

    #   type: in-text

    #

    # TARGET_PATH:

    #   name: Target file path to append to

    #   position: A5:F5

    #   type: in-text

    #

    ###

     

    $script:ErrorActionPreference = "Continue"

     

    $cmd_to_exec = $env:COMMAND_TO_EXECUTE

    $cmd_to_exec1 = $env:COMMAND_TO_EXECUTE1

    $cmd_to_exec2 = $env:COMMAND_TO_EXECUTE2

    $cmd_to_exec3 = $env:COMMAND_TO_EXECUTE3

     

    if ($env:TARGET_PATH.Length -gt 1) {

      cd $env:TARGET_PATH

    }

    Write-host "1-Executing $cmd_to_exec"

    CMD /c $cmd_to_exec

    if ($cmd_to_exec1.Length -gt 2 ) {

      Write-host "2-Executing $cmd_to_exec1"

      CMD /c $cmd_to_exec1

      }

    if ($cmd_to_exec2.Length -gt 2 ) {

      Write-host "3-Executing $cmd_to_exec2"

      CMD /c $cmd_to_exec2

      }

    if ($cmd_to_exec3.Length -gt 2 ) {

      Write-host "4-Executing $cmd_to_exec3"

      CMD /c $cmd_to_exec3

      }