taT4Py | Convert AutoSys Job Attributes into Python Dictionary

[UPDATE: 09/28/2014]

If you ever look at the definition of specific AutoSys Job, you would find that it contains attribute-value pairs (line-by-line), delimited by colon ‘:’ I thought it would be cool to parse the job definition, by creating python dictionary using the attribute-value pairs.

Let us take a look at sample job definition;

$> cat sample_jil
insert_job: A0001
command: echo "Hi"
condition: s(B0001, 03\:00) & v(SRVR) = "UP"
std_out_file: >/home/nvarun/outfile
std_err_file: >/home/nvarun/errfile
group: NV

Getting Started

To convert this into Python Dictionary, execute ignore the following command;

$> sed "s/^\([^:]*\):\(.*\)$/'\1':'\2'/" sample_jil > sample_pydict
$> cat sample_pydict
'insert_job':' A0001
'command':' echo "Hi"'
'condition':' s(B0001, 03\:00) & v(SRVR) = "UP"'
'std_out_file':' >/home/nvarun/outfile'
'std_err_file':' >/home/nvarun/errfile'
'group':' NV'

We are half-way through, to complete the conversion, write following steps in python script and populate dictionary as follows;

import string
jobDefn = {}
with open('sample_pydict', 'r') as f:
    for line in f.read().splitlines():
        colon = string.find(line, ':')
        key = line[:colon]     ##string.replace(line[:colon], "'", "")
        val = line[colon+1:].strip()
        jobDefn[key] = val        
print jobDefn

[UPDATE: 09/28/2014]

As per Antonio’s comments, one can optimize the code as follows, by ignoring sed as well;

import string
jobDefn = {}
with open('sample_pydict', 'r') as f:
    for line in f:
        key, val = line.split(':')
        jobDefn[key] = val.strip()
print jobDefn

However, there are chances when the values might contain ‘:’ as well, you could switch back to the earlier solution. Otherwise, invoking split() as above, throws ValueError: too many values to unpack.


  1. Using f.read() reads the input file at one go and invoking splitlines() splits the input into list of several lines, resulting in creating an iterator.
  2. The for-statement iterates over each line from file object wherein position of first occurrence of colon is found and used for extracting key, value based on slicing and invokes split() to determine key, value.
  3. At the end of the loop, the dictionary object jobDefn is printed.

Hope this helps.


AutoSys Jobs, ZQL and Oracle Database

Since few months, I have been dealing with AutoSys Jobs at workplace and so far, have been running sendevent commands for triggering the AutoSys Jobs to handle commonly used scenarios, covered as follows;


However, time had come that I started modifying the AutoSys Job definition using JIL, i.e. Job Information Language. So, to gain better understanding I started referring Unicenter AutoSys Job Management Reference Guide and have been exploring ever since.

AutoSys Relational Database

The interesting thing to know, the AutoSys Jobs definition, runtime information, etc is stored in Oracle Database and the guide states the following;

Because Unicenter AutoSys JM uses a relational database, you can query the database to supply custom reports and information.

Note: Using SQL commands to change information in Unicenter AutoSys JM tables may cause your system to fail. The Unicenter AutoSys JM tables and views listed in the following sections are for documentation purposes only. They are not intended to be used as a public interface and are subject to change between releases.

By default, the Unicenter AutoSys JM OS user is “autosys”. However, you may define a different ID for the OS user during installation.

So, the query language used for querying purpose is known as ZQL.


If your Unix server has AutoSys installed, chances are you can view man pages as well for ZQL. I will give a brief overview in this blog post, through following ZQL query I wrote recently;

<database>.ujo_jobst A,
<database>.ujo_intcodes B
A.job_type = '<job_type-attribute>'
A.as_group = '<group-attribute>'
A.status = B.code

You may click on the hyperlink in the above query to learn more about the table/view definitions.

The column ujo_jobst.as_group (pulled from ujo_job2 table) contains the group information, which is usually specified in defining the AutoSys Job as follows;

group: <group-name>

The column ujo_jobst.job_type (pulled from ujo_job table) is straight-forward, contains either b/c/f, depending on whether its a Box/Command/File Watcher AutoSys Job.

job_type: b

The table ujo_intcodes, contains 3 columns only and code column is equivalent to the ujo_jobst.status column. So, the ujo_intcodes.text column contains values corresponding to each code like RUNNING, ACTIVATED, INACTIVE, FAILURE, etc.

As a result, I have pulled a report by executing ZQL script, having group-specific box AutoSys jobs along with their current status 😉