Saturday 28 September 2024

How to Create a Job in AutoSys

 # 


AutoSys is an advanced job scheduling tool used to automate, schedule, and monitor IT processes. One of the core functions is creating jobs that define tasks to be executed on a machine or server. To create a job in AutoSys, we use **Job Information Language (JIL)**. This guide will walk you through the essential steps for creating a job using JIL in AutoSys.


## What is JIL?


JIL stands for **Job Information Language**. It is a scripting language that is used to define jobs and job attributes within AutoSys. You can write JIL scripts to create new jobs, update existing jobs, or delete jobs.


## Basic Structure of a JIL File


Here is the basic structure of a JIL file for creating a job in AutoSys:


```jil

insert_job: <job_name> job_type: <job_type>

command: <command_to_run>

machine: <machine_name>

owner: <user_id>

permission: <permissions>

date_conditions: <yes/no>

days_of_week: <days>

start_times: "<start_time>"

description: "<job_description>"

std_out_file: "<output_log_file>"

std_err_file: "<error_log_file>"

```


### Key Attributes:

- **insert_job**: The name of the job you are inserting into AutoSys. This should be unique.

- **job_type**: Defines the type of job. Common types include:

  - `c`: Command

  - `b`: Box

  - `f`: File watcher

- **command**: The command that will be executed on the target machine (e.g., a shell script, binary, or program).

- **machine**: The name of the machine or server where the job will run.

- **owner**: The user who will execute the job on the machine.

- **permission**: Defines access permissions (e.g., `gx` for group execute or `mx` for machine execute).

- **date_conditions**: Set to `yes` if the job should have scheduling conditions based on dates or times, or `no` if it will be triggered based on other conditions.

- **days_of_week**: Specifies the days when the job should run (e.g., `mo,tu,we,th,fr` for weekdays).

- **start_times**: Specifies the time when the job should start (e.g., `12:00`).

- **description**: A brief description of what the job does.

- **std_out_file**: The file where the standard output of the job will be logged.

- **std_err_file**: The file where the standard error will be logged.


## Steps to Create a Job in AutoSys


### 1. Write the JIL Script

The first step in creating a job is to write the JIL script containing the job definition. Let’s take an example of creating a job that runs a shell script on a specific machine every Monday at 10 AM.


```jil

insert_job: my_job_001 job_type: c

command: /path/to/your_script.sh

machine: myserver

owner: user@myserver

permission: gx,wx,mx

date_conditions: yes

days_of_week: mo

start_times: "10:00"

description: "This is a sample job that runs a shell script."

std_out_file: /path/to/output/log/file.out

std_err_file: /path/to/error/log/file.err

```


This JIL file creates a job named `my_job_001` that runs the `your_script.sh` script every Monday at 10 AM on the server `myserver`.


### 2. Use the JIL Command Line Interface

Once you have the JIL script ready, the next step is to insert the job into AutoSys. You can use the `jil` command to load and execute the script. 


1. Log in to the server where AutoSys is installed.

2. Enter the following command to start the JIL interface:


```bash

jil

```


3. Copy the JIL script into the terminal and press Enter. Alternatively, you can save the JIL script in a file and load it by redirecting the file to the `jil` command:


```bash

jil < job_definition.jil

```


### 3. Verify the Job

Once the job is inserted, you can use the `autorep` command to verify that the job has been successfully created in AutoSys.


```bash

autorep -j my_job_001

```


This command will return the details of the job, including its current status and attributes.


### 4. Monitor the Job

You can monitor the job status and execution using the `sendevent` and `autorep` commands. For example:


- To start the job immediately, you can use:


```bash

sendevent -E FORCE_STARTJOB -J my_job_001

```


- To check the status of the job, use:


```bash

autorep -j my_job_001

```


## Common Job Types in AutoSys


1. **Command Job** (`c`): Executes a command or script.

2. **Box Job** (`b`): A container for other jobs that are grouped logically.

3. **File Watcher Job** (`f`): Waits for a specific file to arrive or be modified.


## Job Dependencies

AutoSys supports job dependencies, allowing you to chain jobs together. For instance, you can set up one job to trigger after another job completes successfully. This can be achieved by adding the `condition` attribute to your JIL file.


Example:


```jil

insert_job: dependent_job job_type: c

command: /path/to/another_script.sh

machine: myserver

owner: user@myserver

permission: gx,wx,mx

date_conditions: no

condition: success(my_job_001)

```


In this example, `dependent_job` will only run if `my_job_001` completes successfully.


## Conclusion

Creating a job in AutoSys using JIL is a straightforward process once you understand the key attributes and commands. The flexibility of JIL allows for complex scheduling, dependency management, and job monitoring. By following the steps outlined above, you can create, schedule, and monitor jobs effectively within AutoSys.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.