Skip to content
Home
Products
Solutions
Customers Enterprise Community Docs
Support
Live Demo

Job Platform Script Development

The OpsAny job platform supports Shell, Python, BAT and PowerShell scripts for batch automated remote execution. You can build scripts for a wide range of operational scenarios — for example, patch management can be implemented as a job orchestration that first distributes files and then runs a script.

Tip

All script types report the status of the last command executed as the final status of the script, so handle this yourself inside the script.

Writing Shell Scripts

Shell scripts have three built-in functions — start (job_start), success (job_success) and failure (job_fail) — that you can call from your script, for example to evaluate execution status with if.

#!/bin/bash
#------ built-in helper functions, call them directly ------
anynowtime=$(date +'%Y-%m-%d %H:%M:%S')
NOW="echo [$anynowtime][PID:$$]"

# Call at the start of the script to print the current timestamp and PID.
job_start(){
    echo "$(eval $NOW) job_start"
}

# Call on the success branch to print the current timestamp and PID.
job_success(){
    MSG="$*"
    echo "$(eval $NOW) job_success:[$MSG]"
    exit 0
}

# Call on the failure branch to print the current timestamp and PID.
job_fail(){
    MSG="$*"
    echo "$(eval $NOW) job_fail:[$MSG]"
    exit 1
}

job_start
#------ write your own script logic below this line ------

Writing Python Scripts

Python scripts have the same three built-in functions — start (job_start), success (job_success) and failure (job_fail) — that you can call directly.

#!/usr/bin/env python3
# -*- coding: utf8 -*-

import datetime
import os
import sys

def _now(format="%Y-%m-%d %H:%M:%S"):
    return datetime.datetime.now().strftime(format)

# Call at the start of the script to print the current timestamp and PID.
def job_start():
    print("[%s][PID:%s] job_start" % (_now(), os.getpid()))

# Call on the success branch to print the current timestamp and PID.
def job_success(msg):
    print("[%s][PID:%s] job_success:[%s]" % (_now(), os.getpid(), msg))
    sys.exit(0)

# Call on the failure branch to print the current timestamp and PID.
def job_fail(msg):
    print("[%s][PID:%s] job_fail:[%s]" % (_now(), os.getpid(), msg))
    sys.exit(1)

if __name__ == '__main__':
    job_start()

We recommend storing scripts in the script repository, then simply selecting a script from the repository when running a job.

Document