Automic Workload Automation

Expand all | Collapse all

How to set variable value from unix command's return

  • 1.  How to set variable value from unix command's return

    Posted Jan 08, 2015 08:49 AM
    I want to send e-mail notifications when there are files found in remote server's directory. Agent is installed on remote server.
    JOBS gets &DIR# as variable "/path/to/directory"
    JOBS Process tab:
    cd &DIR# ls -1 | wc -l
    JOBS Post Process tab:
    :SET &hnd# = PREP_PROCESS_REPORT(,,REP,) :PROCESS &hnd# :  SET &line# = GET_PROCESS_LINE(&hnd#) :  IF STR_FIND(&line#,"*") > 0 :    IF &line# = 0 :      SET &OUT# = SEND_MAIL('me@example.com',,'Found &line# files','Found &line# files in &DIR#!',) :    ENDIF :  ENDIF :ENDPROCESS
    This is shown in Report after JOBS execution:
    ************************************************************************ **  ucxjlx6m   version 10.0.2+build.624         changelist 5277596    ** **  JOB 01043032 (ProcID:0000014241) START AT 08.01.2015 / 15:31:04   ** **                                   UTC TIME 08.01.2015 / 13:31:04   ** **  TEXT="        Job started             "                           ** ************************************************************************ 23 ************************************************************************ **  ucxjlx6m   version 10.0.2+build.624         changelist 5277596    ** **  JOB 01043032 (ProcID:0000014241) ENDED AT 08.01.2015 / 15:31:04   ** **                                   UTC TIME 08.01.2015 / 13:31:04   ** **  TEXT="        Job ended               "  RETCODE=00               ** ************************************************************************
    And I receive an email.

    TL;DR:
    Is there any easy way to get response from unix script as variable?
    Like
    &COUNT# = "ls -1 | wc -l"
    , but not as text, but command's response.


  • 2.  How to set variable value from unix command's return

    Posted Jan 08, 2015 11:30 AM

    I do not know of an easy way.  If there is, I could certainly use it too.



  • 3.  How to set variable value from unix command's return

    Posted Jan 08, 2015 12:07 PM

    Well, depending on the operating system and the maximum number of files found in this particular example, you could set the return code on exit from the shell to that number.  In Unix, depending on the flavor, I believe that the maximum value is 255.  You could then use the GET_STATISTIC_DETAIL and retrieve theRETURN_CODE as the value.  However, this technique may affect your task’s Runtime Ended_OK processing and obscure other processing errors.

    Though I’ve never tried it, I guess that you could call the API from your program and do an RSET of a script variable or store the value in a Variable so it would be available to the Post Process.  There is also the Output Scan, but that is again something that I have no experience with and don't know all of its capabilities and limitations.

    Using the PREP_PROCESS_REPORT technique is at least the most obvious and is "passive" and can be used with great reliability.  It is the technique that we have standardized on when needing this type of logic.



  • 4.  How to set variable value from unix command's return

    Posted Jan 09, 2015 03:44 AM
    Setting RETURN_CODE to number of files does not feel right, and this morning there were 622 files in directory. If RETURN_CODE max number is 255 then I can't use this solution anyway.

    I took a look on Output Scan feature, but I think it isn't meant for parsing output to variables. It's more for parsing output for containing (or NOT containing) certain keywords (ex. "File not found") and reacting by executing other objects (messaging, other jobs, etc.).

    I think I'll stay with PREP_PROCESS_REPORT solution for now. Maybe in next AE versions developers will introduce functionality where we will be able to set unix script's output as variable directly by calling something like ":SET &COUNT# = `ls -1 | wc -l`.
    Thanks for your time!


  • 5.  How to set variable value from unix command's return

    Posted Jan 09, 2015 12:10 PM
    >@</p>Edgars Voroboks"  Feel free to make a post in the Product Ideas section with your thoughts. 


  • 6.  How to set variable value from unix command's return

    Posted Jan 09, 2015 10:20 PM
    Yes, I think it would have to be a product Idea/change.

    All Script code is executed to create all the JCL Lines, this is done before the "Job" ever runs on the Agent.  So there is currently no way for a script line to execute and store the result immediately.  The POST PROCESS tab is the main way to react to output from the PROCESS tab (STDOUT/STDERR).


  • 7.  How to set variable value from unix command's return

    Posted Jan 13, 2015 05:50 AM
    Hello, if it's not necessary to use a UNIX job for counting the files, then the easiest way is the GET_FILESYSTEM command. Just replace the UNIX job with a Automic Script-Object and put something like this into it: :SET &FILECOUNT# = GET_FILESYSTEM(<your>, "&DIR#", PATH_FILE_COUNT,,N) :SET &FILECOUNT# = FORMAT(&FILECOUNT#) then you can use the &FILECOUNT# variable </your>


  • 8.  How to set variable value from unix command's return

    Posted Jan 19, 2015 04:23 PM
    Hi all, I found out that in v11.1, they've added this functionality. 
    Users will be able to use native scripting to save values to a Automic Script Variable.

    v11.1 should be out at the end of the month. I'll make a post when the Documentation is available online. 


  • 9.  How to set variable value from unix command's return

    Posted Jan 20, 2015 02:06 AM
    Nice find Jennifer. I was going to fill Product Ideas form today, but read your comment. Will try this functionality when v11.1 is out and write about it.


  • 10.  How to set variable value from unix command's return

    Posted Feb 16, 2015 03:20 PM
    Hi All, ONE Automation 11.1 is now available. Here's the post about it.




  • 11.  How to set variable value from unix command's return

    Posted Sep 24, 2015 07:27 AM
    You can do this by using VARA.BACKEND, setting Linux command there and later in JOBS object's Process tab getting this variable:
    :SET &LINES# = PREP_PROCESS_VAR(VARA.BACKEND.VALUE);
    :PROCESS &LINES#
    :  SET &MYVAR# = GET_PROCESS_LINE(&LINES#, 1)
    :ENDPROCESS

    Automic v11.1 - we found bugs there and decided to stay with v10.


  • 12.  How to set variable value from unix command's return

    Posted Sep 28, 2015 03:12 PM
    Hi @"Edgars Voroboks" 

    Can you tell us a little more about 
    VARA.BACKEND? Is this a special VARA? I could not find any reference to it in docs or in Automic system. What do you mean "setting Linux command there?"


  • 13.  How to set variable value from unix command's return

    Posted Sep 29, 2015 03:26 PM
    eric.felker 

    The VARA.BACKEND is one of the VARA that is available for use, it should be available within your Automic System.
    wicakes3bmlo.png
    There is not much information of it within the document but it does mention it, here.



  • 14.  How to set variable value from unix command's return

    Posted Sep 29, 2015 03:34 PM
    Luu Le said:
    eric.felker 

    The VARA.BACKEND is one of the VARA that is available for use, it should be available within your Automic System.

    There is not much information of it within the document but it does mention it, here.


    Ah, after seeing it again, I know I've come across it while looking up something else, but had completely lost it by now. Also, more information on it HERE.