Automic Workload Automation

  • 1.  Storing Unix command output in a variable

    Posted Jul 18, 2017 04:23 AM
      |   view attached
    I am looking for output of Unix command to be stored in any variable. Generally we use POST process to do so , however , as this is "INCLUDE" object I am not able to store.
    PUT_VAR does not work as that stores the command itself - not command output.

    1. You may use PREP_PROCESS in the INCLUDE object to run an OS command  :
    :SET &HND# = PREP_PROCESS("&$AGENT#","UNIXCMD",,"CMD=echo $SHELL","UC_LOGIN=&$LOGIN#")
    :PROCESS &HND#
    :  SET &SHELL# = GET_PROCESS_LINE(&HND#)
    :  P &SHELL#
    :ENDPROCESS

    2. You can also use a BACKEND variable to run the command, then collect its output with GET_VAR or PREP_PROCESS_VAR in the include object as well.

    ahbjvixfnyld.pnghttps://us.v-cdn.net/5019921/uploads/editor/3i/ahbjvixfnyld.png" width="668">

    INCLUDE
    :SET &SHELL# = GET_VAR(VARA.BACKEND.UNIX.CMD)
    :P &SHELL#

    Here's the output:
    diuwekkeeil6.pnghttps://us.v-cdn.net/5019921/uploads/editor/e2/diuwekkeeil6.png" width="310">

    I'm attaching an xml export of example objects.

    Best regards,
    Antoine

    Attachment(s)



  • 2.  Storing Unix command output in a variable



  • 3.  Storing Unix command output in a variable

    Posted Jul 18, 2017 04:42 AM
    You're right FrankMuffke , even simpler and faster :)

    Way #3:
    :REGISTER_VARIABLE "SHELL#", $SHELL


  • 4.  Storing Unix command output in a variable

    Posted Jul 18, 2017 04:44 AM
    I know  :p

    THX for the example.


  • 5.  Storing Unix command output in a variable

    Posted Jul 18, 2017 05:15 AM

    We had tried BACKEND VARA , however were unclear about the “Result format” , could you help me with example ? if possible use echo $SHELL or ps –p  ?

    Entries in the "Columns" have to follow a certain syntax :

    ColumnName:<starting point>(length)

    For instance:

    o3esn66nwfpt.pnghttps://us.v-cdn.net/5019921/uploads/editor/p6/o3esn66nwfpt.png" width="508">

    Will return results in a single column named "Result", starting with character '1' and 255 characters long:

    lcf6ubyo00k5.pnghttps://us.v-cdn.net/5019921/uploads/editor/jf/lcf6ubyo00k5.png" width="1152">

    You can choose to set different columns with different starting points and lengths so the output is easier to read, and different values can be read with GET_VAR(&HND#,column number) - or PREP_PROCESS_VAR(&HND#,column number).


    Syntax has to be like this:

    Column1Name:<starting point>(length);Column2Name:<starting point>(length)[Column3Name:<starting point>(length)]...[ColumnNName:<starting point>(length)]

    Example : raw command on Linux side

    jzkz4hog4tcg.pnghttps://us.v-cdn.net/5019921/uploads/editor/to/jzkz4hog4tcg.png" width="608">

    Define columns in the VARA.BACKEND :

    54cv8r16f03t.pnghttps://us.v-cdn.net/5019921/uploads/editor/22/54cv8r16f03t.png" width="838">

    and the output will look like this:

    qlniuewy952g.png

    Foot note : just to confirm, "echo $SHELL" works:

    jymmouhlzjry.pnghttps://us.v-cdn.net/5019921/uploads/editor/qj/jymmouhlzjry.png" width="460">

    Best regards,
    Antoine


  • 6.  Storing Unix command output in a variable

    Posted Jul 18, 2017 06:25 AM
    I put together a few practical examples of how to use :REGISTER_VARIABLE.