iamintown

Autosys Jobs Creation Python Script

Blog Post created by iamintown on Apr 7, 2015

#!/usr/bin/python

#The script is to create a basic jobs in Autosys.

#Written by dosman on 04/07/15

import fileinput,sys,re,os

def insertjob():

        cmddev = "/bin/bash -c 'source /opt/CA/WorkloadAutomationAE/autouser.DEV/autosys.bash.devpmpoc1 && jil < /tmp/out.jil'"

        cmdbet = "/bin/bash -c 'source /opt/CA/WorkloadAutomationAE/autouser.BET/autosys.bash.devpmpoc1 && jil < /tmp/out.jil'"

        cmdprd = "/bin/bash -c 'source /opt/CA/WorkloadAutomationAE/autouser.PRD/autosys.bash.devpmpoc1 && jil < /tmp/out.jil'"

        print "Enter Autosys Environment DEV or BET or PRD"

        aenv = raw_input('Enter Autosys Environemnt Name: ')

        if aenv == "DEV":

          print "its DEV Autosys"

          os.system(cmddev)

          print cmddev

        elif aenv == "BET":

           print "its BETA Autosys"

           os.system(cmdbet)

           print cmdbet

        elif aenv == "PRD":

          print "its PROD Autosys"

          os.system(cmdprd)

          print cmdprd

        else:

          print "Need correct Autosys Environment name DEV/BET/PRD"

 

 

#insertjob()

def createfile():

        print "Enter Autosys Job name, follow the job naming standard"

        jname = raw_input('Enter Autosys Job Name: ')

        mname = raw_input('Enter Autosys Machine Name: ')

        uname = raw_input('Enter Autosys ServiceAccount Name: ')

        print "Enter Command, usually its a shell/perl/python/powershell/batch script with complete path"

        cname = raw_input('Enter Autosys Command: ')

        jobname = 'insert_job: ' + jname

        machinename = 'machine: ' + mname

        owner = 'owner: ' + uname

        command = 'command: ' + cname

        print jobname

        orig_stdout = sys.stdout

        f = file('/tmp/out.jil', 'w')

        sys.stdout = f

        for i in (jobname, machinename, owner, command):

                print  i

 

 

        sys.stdout = orig_stdout

        f.close()

createfile()

insertjob()

print "Inserting job"

def addjob():

        while True:

                print("Do you want to create additional jobs")

                res = raw_input(" Hit y for yes or n for no\n")

                if  res in ("y" or "Y"):

                        createfile()

                        insertjob()

                        print "Inserting job"

                        cmd2='jil < /tmp/out.jil'

                elif  res == ("n" or "N"):

                        break

                else:

                        print "command"

addjob()

Outcomes