AutoSys Workload Automation

  • 1.  Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 10-08-2014 02:10 AM

    This script (jobsForMachine.py) will return a list of jobs for the machine specified.

    #!/usr/bin/python

     

    import sys

     

    requested_machine = sys.argv[1]

    j = {}

     

    def printResults():

      for job, machine in j.items():

        if machine == requested_machine:

          print job, '->', machine

     

    for line in sys.stdin:

      if 'job_type' in line:

        jobName = line.split()[1]

      if 'machine' in line:

        j[jobName] = line.split()[1]

    printResults()

     

    Here is an example run for machine "sun10" with output:

     

    -bash-3.00$ autorep -J ALL -q | jobsForMachine.py sun10

    B999999996 -> sun10

    B999999998 -> sun10

    TEST123_ -> sun10

    TEST_123 -> sun10

    sched -> sun10

    testjob -> sun10

    lbjob3 -> sun10

    lbjob2 -> sun10

    lbjob1 -> sun10

     

    This script (jobTotalByMachine.py) will return total number of jobs defined per machine.

    #!/usr/bin/python

     

    import sys

     

    j = {}

     

    def printResults():

      results = {}

      for job, machine in j.items():

        if machine in results:

          results[machine] = results[machine] + 1

        else:

          results[machine] = 1

      print results

     

    for line in sys.stdin:

      if 'job_type' in line:

        jobName = line.split()[1]

      if 'machine' in line:

        j[jobName] = line.split()[1]

    printResults()

     

    Here is an example run with output:

     

    -bash-3.00$ autorep -J ALL -q | jobTotalByMachine.py

    {'sun12': 7, 'sun11': 5, 'sun10': 9, 'U103827': 3, 'nosnah137': 1, 'localhost': 1}

     

    The fine print:

    Developed and lightly tested using Python 2.4.4 on Solaris.

    These scripts are provided "as-is", without warranty of any kind, etc. etc.



  • 2.  Re: Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 01-15-2015 11:09 AM

    Thanks. I  was trying to figure is out for long time.



  • 3.  Re: Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 02-04-2015 08:45 PM

    Here is an alternative, using shell and Perl (one liner):

     

    NOTES:

    1) Multiple machine names are allowed (comma separated).

    2) THIS ONE FINDS JOBS THAT ARE DEFINED ON MACHINES STARTING WITH THE NAMES PASSED. "LOD" will find "LODHP01" and "LODSUN1" and so on.

     

    Usage: ./getJobsByMach.sh machine1[,machine2,..,machineN]

    (No white space after comma, please)

     

    Example:

    sh-4.1# ./getJobsByMach.sh localhost,lodhp01
    Job name: CMD1
    RunMachine: localhost

    Job name: CMD2
    RunMachine: localhost

    Job name: test_invalid_TZ
    RunMachine: localhost

    Job name: future_date
    RunMachine: localhost

    Job name: 21957774_hpux_agent_kill-15
    RunMachine: lodhp01

    Job name: test_perl
    RunMachine: localhost

    Job name: 21989472_n_retry_test
    RunMachine: localhost

     

    Script:

     

    sh-4.1# cat getJobsByMach.sh
    #!/bin/sh
    #Source the autosys profile
    . /opt/CA/WorkloadAutomationAE/autouser.CVC/autosys.sh.`hostname`

    #Ensure there is atleast one machine name passed as argument

    if [ $# -eq 0 ]
    then
            echo -e "\nSorry, what am I supposed to search for? You haven't given any machine name\n"
            echo -e "Usage: $0 machine1[,machine2,..,machineN]\n"
            echo -e "(No white space after comma, please)\n"
            exit 1
    fi

    MACH_LIST=`echo -e $1 | sed -e 's/,/|/'`
    MACH_LIST="$MACH_LIST"
    do_the_search()
    {
            PERL_LINE="$(which perl) -00 -ne"
            $AUTOSYS/bin/autorep -J ALL -q | \
            $PERL_LINE "print if /machine:\s($MACH_LIST)/" | \
            egrep '(^$|insert_job:|machine:)' | \
            sed -e 's/insert_job:/Job name:/' -e 's/job_type:.*//' -e 's/machine:/RunMachine:/'
    }

    do_the_search

    #THE END

     

    The fine print: These scripts are provided "as-is", without warranty of any kind, etc. etc.



  • 4.  Re: Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 04-07-2015 06:01 PM

    thanks a lot, work like a charm...

    jr  ALL -q |python job-specific-machine.py devpmapp1



  • 5.  Re: Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 04-07-2015 06:19 PM

    This can also be accomplished with the WCC Quick Edit.  Populate the Job field with * and the name of the machine in the Machine field.



  • 6.  Re: Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 04-07-2015 07:14 PM

    Thanks Gregg....



  • 7.  Re: Tuesday Tip: AutoSys - Get a list of jobs defined for a specified machine

    Posted 04-09-2015 01:22 PM

    is this for the autosys admin/engineer or for a typical user?

    admin/engineer,

    use SQL.

    for typical user. if you are trying to see if the machine is currently being used.

    autorep -d -M machine

    Otherwise, JAWS etc can assist with a better view into this .. otherwise teh py and perl altneratives are good for poor man info grabs.

     

    Steve C.