Automic Workload Automation

 View Only
  • 1.  Running 2 Command lines in a single Job.

    Posted Dec 05, 2024 04:28 PM

    Hi All,

    We're mainly trying to achieve out here is have 2 command lines in same Job and if 1st command line gets failed with Return code 1 then it needs to execute 2nd command line(either through Process or Post process) instead of running through another job.

    Can some one help us out here. Thanks in Advance.



  • 2.  RE: Running 2 Command lines in a single Job.

    Posted Dec 05, 2024 06:14 PM
    Edited by Daryl Brown Dec 05, 2024 06:19 PM

    Is this a unix job or windows job?  It'll help in providing an example...

    But for example, if it's unix:

    echo "running command 1."
    ./command1.sh
    retval=$?
    echo "return code = $retval"
    echo ""
    if test $retval -eq 1
    then
      echo "command 1 failed.  Running command 2."
      ./command2.sh
      retval=$?
      echo "return code = $retval"
    fi
    (exit $retval)

    Obviously, you can replace './command1.sh' and './command2.sh' with whatever is appropriate in your case.




  • 3.  RE: Running 2 Command lines in a single Job.

    Posted Dec 05, 2024 06:36 PM
    Edited by pavan shashikanth guddeti Dec 05, 2024 07:33 PM

    Hi Daryl,

    Thanks for you're response. It's a Windows JOB .Can I know if it needs to be placed in Process tab or Post process tab?




  • 4.  RE: Running 2 Command lines in a single Job.

    Posted Dec 05, 2024 06:50 PM
    Edited by pavan shashikanth guddeti Dec 05, 2024 07:32 PM

    Hi Daryl,

    I made a wrong question earlier actually its 3 commands and its Windows Job.

    If Command 1 returns return code as 0 then its needs to run one set of command.

    If command 1 return return code as 1 then its needs to  run one set of command.

    Could you please Help me with you're Updated script.Thanks in Advance.




  • 5.  RE: Running 2 Command lines in a single Job.

    Broadcom Employee
    Posted Dec 06, 2024 07:22 AM

    Hi,

    what about using the IF-Workflow instead?

    Documentation - IF Workflow

    Regards, Markus




  • 6.  RE: Running 2 Command lines in a single Job.

    Posted Dec 06, 2024 09:22 AM

    Thank you Markus for you're reply.

    But we're looking for an approach which Daryl shared earlier mainly for a Windows Job which fits as per our needs.




  • 7.  RE: Running 2 Command lines in a single Job.

    Posted Dec 06, 2024 09:28 AM
    Edited by Daryl Brown Dec 06, 2024 09:30 AM

    This is all code that would be placed in the process tab.  (The post process tab is best used for evaluating how everything played out on the Process tab, but not so useful for kicking off new scripts unless you want to use ACTIVATE_UC_OBJECT or PREP_PROCESS.)

    So for windows, I would try something like this:

    echo running command 1.
    call command1.cmd
    set retcode=%errorlevel%
    echo return code = %retcode%
    echo.
    if %retcode% == 0 goto :run_command_1b
    if %retcode% == 1 goto :run_command_2
    goto :done

    :data :run_command_1b
    echo running command 1b.
    call command1b.cmd
    set retcode=%errorlevel%
    echo return code = %retcode%
    echo.
    goto :done

    :data :run_command_2
    echo running command 2.
    call command2.cmd
    set retcode=%errorlevel%
    echo return code = %retcode%
    echo.

    goto :done

    :data :done
    if not %retcode% == 0 goto :retcode

    As before, you'll want to change the 'call command*.cmd' references to whatever your appropriate commands are.

    Note that if you need to be able to figure out, for the sake of your overall workflow, which commands you actually ended up running (e.g., command 1 + command 1b vs command 1 + command 2), then that's the kind of thing you could use the Post Process tab for.  You could use PREP_PROCESS_REPORT to analyze your report output and look for certain strings to confirm which scenario took place.

    One other thing to be mindful of is when you combine a series of commands into a single job like this, it can make restarting the job more complicated (e.g., if you want to just restart command2 without having to rerun command1 again also).  @Markus Embacher's suggestion about using an IF workflow is one way to address this...although that goes against your requirement to have everything contained in a single job.  Another option would be to create restart points within your windows script -- check out the documentation on the :RESTART function to see if this might be useful.




  • 8.  RE: Running 2 Command lines in a single Job.

    Posted Dec 06, 2024 09:33 AM

    Thank you Daryl for sharing it which is much helpful.