Automic Workload Automation

 View Only
Expand all | Collapse all

PREP_PROCESS - no STDOUT

  • 1.  PREP_PROCESS - no STDOUT

    Posted Apr 25, 2018 10:29 AM

    Hello,

     

    i have a question with the PREP_PROCESS() Function:

     

    ! Set view
    set -x
    ! Create a file with hallo inside
    echo hallo > /home/automic/hallodatei.txt
    ! List to see if the file exists
    ls -l /home/automic/hallodatei.txt
    ! Read the File
    cat /home/automic/hallodatei.txt

     

    _______CUT______

     

    ! Read the file now with the PREP_PROCESS
    :SET &HND# = PREP_PROCESS("UNIX01","UNIXCMD",,"CMD=cat /home/automic/hallodatei.txt","UC_LOGIN=LOGIN.ALL")
    :PROCESS &HND#
    : SET &LINE# = GET_PROCESS_LINE(&HND#)
    :ENDPROCESS

     

    So i create a file with "hallo" inside and then i just read the file. 

    That works fine. 

    ______CUT______

    now - i need to do this with PREP_PROCESS but there is no STDOUT in the &HND#.

     

    When i play with "echo hello" instead of "cat .....txt" i see the "hello" in the PROCESS &HND#

     

    The Main Idea behind this is that i want to delete files with the HOST command. 

    I have to know if the file has been deleted correct. IF the deletion was correct i want to clean a VARA Object. 

    Of course, i could call another JOBS which delete the file and check the STATUS from that job - BUT - there is PREP_PROCESS which could allow me to do that in ONE Script. Would be great and useful for future actions! 

     

    (PS: i am in the SCRIPT Course and here we all don´t know why the STDOUT sometimes is in the &HND# and why sometimes not)



  • 2.  Re: PREP_PROCESS - no STDOUT

    Posted Apr 26, 2018 04:25 AM

    Good morning

     

    I use prep_process+ OS command hevily and did not observe such a behavior so far.

     

    short test script:

    :SET &FILE# = "/tmp/deleteme.txt"
    :SET &CMD# = "cat &FILE#"
    :SET &HND# = PREP_PROCESS(&AGENT#,UNIXCMD,"*","CMD=&CMD#","UC_LOGIN=&LOGIN#")
    :PROCESS &HND#
    :  SET &LINE# = GET_PROCESS_LINE(&HND#)
    :  PRINT &LINE#
    :ENDPROCESS
    :CLOSE_PROCESS &HND#

     

    results in:

    2018-04-26 10:18:33 - U00007000 'EVENT.UNIXCMD' activated with RunID '0295876151'.
    2018-04-26 10:18:33 - U00020408 UC4isGreat

     

    Can you please post your whole script and he info which AE version and which linux version you are using?

     

    another hint: be careful if your OS part of the prep process returns an RC > 0 here by default you get a strange error message "file not found".

    I this case EVENT.UNIXCMD should be modified accordingly.

     

    cheers, Wolfgang



  • 3.  Re: PREP_PROCESS - no STDOUT

    Posted Apr 26, 2018 05:50 AM

    Hi,

    thank you for your reply.

     

    is used your short test and it worked great. 

    We use 12.0 in the script course right now. 

     

    i dont receive an answer from deleting a file when the file isn´t existing.

    So, it could or should tell me that there was an error. But instead another "Filetransfer" (why?!) is crashing.....

     

    This is what i receive when the file is already deleted .... 

     

    4/26/2018 11:49:20
    U00010038 Laufzeitfehler: Datensequenz 'FILETRANSFER' konnte nicht erstellt werden. Status: '0000001820', Rückgabewert: '0000000000'.
    4/26/2018 11:49:20
    U00029003 Die Datei '/home/automic/EAADAZLG.TXT(ReadFileAuthority())' kann nicht geöffnet werden, Fehlercode '2', Fehlerbeschreibung: 'No such file or directory'.
    4/26/2018 11:49:20
    U00011000 'REPORT' (RunID: '0001384803') konnte auf 'UNIX01' nicht gestartet werden. Siehe nachfolgende Meldungen:
    4/26/2018 11:49:20
    U00011003 Job 'EVENT.UNIXCMD' (RunID '0001388121') auf Host 'UNIX01' ist abgebrochen (Rückgabewert='0001'). &06&07 &08&09


  • 4.  Re: PREP_PROCESS - no STDOUT
    Best Answer

    Posted Apr 26, 2018 01:50 PM

    Hi Thomas,

     

    If your Trainer's first name is James pls send him warm greetings from me :-)

     

    The error yo are receiving does not come from your PREP_PROCESS command, we had this a time ago...

     

    Automic is unwilling to fix this "Bug by design" you will find it several times here in community....

     

    Issue description & solution here:

    https://communities.ca.com/message/242096658?commentID=242096658#comment-242096658 

     

    cheers, Wolfgang



  • 5.  Re: PREP_PROCESS - no STDOUT

    Posted Apr 27, 2018 06:44 AM

    Hallo Wolfgang,

     

    yes, it was him

    Unfortunately i cannot send your greeting because the course finished yesterday.

    Thank you for the Link - so i really have to crate that EVNT.UNIXCMD.CUSTOM - i´ll try this - blame that automic doesn´t want to fix this

    Is there a request as Ticket or so to fix this "Design Bug" ? I would vote for that. . . . if you have a link



  • 6.  Re: PREP_PROCESS - no STDOUT

    Posted Apr 27, 2018 01:34 PM

    Hi Thomas

     

    no worries... :-)

     

    regarding Idea - I was sure that I created an Idea in the previous ideation system, at the moment I can not find it, possibly its gone - or never existed..

     

    BTW: If you intend to use EVENT.WINCMD - there is a bug by design as well :-)

     

    cheers, Wolfgang



  • 7.  Re: PREP_PROCESS - no STDOUT

    Posted Apr 30, 2018 04:52 AM

    so i really have to crate that EVNT.UNIXCMD.CUSTOM

    I don't think so. Just add an "or" clause to your UNIX cat statement, like so:

     

     

     

    ! Read the file now with the PREP_PROCESS
    :SET &HND# = PREP_PROCESS("MY_AGENT","UNIXCMD",,"CMD=cat /tmp/testfile.txt || echo deleted","UC_LOGIN=MY.LOGIN")
    :PROCESS &HND#
    : SET &LINE# = GET_PROCESS_LINE(&HND#)
    : PRINT &LINE#
    :ENDPROCESS

     

     

    I tested this on V10, should work on V12 regardless. If your file exists, &LINE# will contain the contents of the file. If your file has been deleted, &LINE# will contain the word "deleted" (or whatever else you specify). In both cases, the job will not abort, it will be ENDED_OK. I think that's what you wanted?

     

    Hth,

    Carsten



  • 8.  Re: PREP_PROCESS - no STDOUT

    Posted May 15, 2018 02:32 AM

    Hi Carsten,

    today i tried your solution but it don´t work for me.

    This works great (i see the text from the file)

     

    But with the "or" (||) it dont work correct:

       -  First Case - The File doesn´t exist:

    Report says --> deleted

       -  Second Case - The File exists!

    The Report says:

     

    Do you have an idea because this solution is so close



  • 9.  Re: PREP_PROCESS - no STDOUT

    Posted May 15, 2018 05:27 AM

    Hi Thomas,

     

    I just revisited this and first, it seems I must offer my apologies: It appears I tested the case for the deleted file with the "or" clause and got ENDED_OK, but I probably tested the "file exists" case when I got ENDED_OK without the "or" clause. That's the only explaination I have because as of today, I am getting the same error you get when the file exists.

     

    It appears Automic runs the shell code in an arbitary way and somehow, unlike the pure shell statement would, it screws up when you have the "or" clause and the file exists. I experimented with an "if" statement instead, but that got even more useless results. On a side note, it appears they also truncate the shell code, which can be demonstrated by using this:

     

    CMD=cat /tmp/testfile.txt ; cat /tmp/testfile.txt

     

    This should print the contents of testfile.txt twice, but it prints it only once. This whole PREP_PROCESS contruct is, in my view, a crutch that follows arbitary rules and I consider it broken, but I'm convincied Automic would argue it's by design.

     

    As for your matter, since they can't do compound commands, you might want to consider putting that command into a shell script and calling that. Either with an "or" or "if" clause that echoes back a string if deletion failed, which you can then process via &HND#. Here's the "if" example:

    #!/bin/bash

     

    if [ -f /tmp/testfile.txt ] ; then

      cat /tmp/testfile

    else

      echo "deleted"

    fi

     

    Maybe you can use $1 as a parameter for the filename and pass that from AE if you want to parameterize the filename.  You'd have to try how badly Automic butchers that command string.

     

    Best regards,

    Carsten



  • 10.  Re: PREP_PROCESS - no STDOUT

    Posted Apr 30, 2018 05:47 AM

    Hi

    we created a modified EVENT.UNIXCMD in every client that ueses PREP_PROCESS.

    UC4[bash]    cat /dev/null > &home#&uc_eventfile

     

    Under some circumstances (with other OC Commands) we got a RC>0 so this solution worked best for us.

     

    cheers, Wolfgang



  • 11.  Re: PREP_PROCESS - no STDOUT

    Posted May 15, 2018 02:49 AM

    I do not say I did tell you.... :-)

     

    honestly we played around with that solution but it didn' t work for us either.

    sry, Carsten...

     

    cheers, Wolfgang