JLI script that uses the output of a BLCLI command in another BLCLI command


The following JLI script example shows how to use an object returned by one BLCLI command in another BLCLI command. In the following example, the JLI script first uses one BLCLI command to get a job key, and then uses that job key to fetch the job schedule through a second BLCLI command.

First BLCLI command


(all on one line)
blcli -v <profile> NSHScriptJob getDBKeyByGroupAndName
"/<static group name>" <job name>

Input (first command)

Static group name to which the job belongs and the job name

Output (first command)

jobKey (Object of type SJobKey)

Second BLCLI command

(all on one line)
blcli -v <profile> Schedule findScheduleDetailsByJobKey 
<Job Key fetched by first command>

Input (second command)

Job Key

Output (second command)

Schedule (as a string)

JLI command

(all on one line)
./bljythonexe "<location of jli script file>"/
 <Static group name>" "Job Name"

Warning

Note

The exact JLI command depends on your operating system:

  • On Windows, use the bljythonexe command.
  • On UNIX, use the bljython command.

Sample script

import sys
import bladelogic.cli.CLI as blcli
#static group name
groupName=sys.argv[1]
#Job name
jobName=sys.argv[2]
jli = blcli.CLI()
jli.setServiceProfileName("<profile>")
jli.setRoleName("<Role>")
jli.connect()
def execute(command):
    print command
    #main CLI command execution.
     propertyObject = jli.run(cmd)
                 
    #If command executed successfully, return the result received after command execution.
    if(propertyObject.success()):
          propertyKey = propertyObject.returnValue
    return propertyKey
#declaring the command array to hold commands to be executed
cmd =[]       
#Getting JobKey for Job named test(NSH Script Job)------------
cmd =[]
print "Command for getting JobKey: "
#Appending namespace for getting job key of an NSH script
cmd.append('NSHScriptJob')
#Appending command
cmd.append('getDBKeyByGroupAndName')
#Appending groupname for the Job
cmd.append( groupName)
#Appending Jobname
cmd.append(jobName)
#Result is returned as a list of servers added.
jobKey = execute(cmd)
print jobKey
#Job key fetched----------------------
#Getting schedule using the above JobKey for the Job -------------
cmd = []
print "\nCommand for getting Schedule: "
#Appending namespace
cmd.append('Schedule')
#Appending command
cmd.append('findScheduleDetailsByJobKey')
#Appending argument JobKey
cmd.append(jobKey)
schedule = execute(cmd)
print schedule
sys.exit(0)


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*

TrueSight Server Automation 22.2