Writing Automation Scripts in REXX Programming Language

Mastering Automation Scripting in REXX: A Comprehensive Guide

Hello, automation enthusiasts! In this blog post, I will introduce you to Operators in REXX Programming – an essential and powerful concept in automation script

ing. Operators play a crucial role in performing calculations, comparisons, and logical operations in REXX. Understanding their syntax and usage is key to writing efficient scripts that execute desired tasks seamlessly. I will guide you through different types of operators, their functionality, and practical examples to enhance your coding skills. By the end, you’ll have a solid grasp of how operators work in REXX, enabling you to write more effective and optimized scripts. Let’s dive in!

Table of contents

An Introduction to Automation Scripting in REXX Programming Language

REXX (Restructured Extended Executor) is a high-level scripting language designed for automation, ease of use, and integration with system processes. Developed by IBM, REXX is widely used in mainframe environments (z/OS, TSO/E, VM/CMS) and also supports other platforms like Windows and Linux. Its simple syntax, powerful string manipulation, and ability to interface with external programs make it an excellent choice for automation.

Automation scripting in REXX enables users to streamline repetitive tasks, manage files, execute system commands, and integrate with databases or other programming languages. It is commonly used for job scheduling, batch processing, report generation, and system administration.

What is Writing Automation Scripts in REXX Programming Language?

REXX (Restructured Extended Executor) is a high-level scripting language developed by IBM, widely used for automation in mainframe environments, OS/2, and other operating systems. It is known for its simplicity, readability, and powerful string-handling capabilities, making it a great choice for automating repetitive tasks.

This guide explores writing automation scripts in REXX with detailed explanations and examples to help you master automation with REXX.

What is Automation in REXX?

  • Automation in REXX refers to writing scripts to perform repetitive tasks, such as:
  • File management (creating, deleting, renaming, copying files)
  • System administration tasks (starting/stopping services, monitoring resources)
  • Data processing (parsing files, extracting data, generating reports)
  • Interaction with other programming languages (calling external scripts, executing shell commands)

REXX provides built-in commands, functions, and I/O operations that make it efficient for scripting and automation.

Getting Started with REXX Automation Scripts

A basic REXX script follows the structure:

/* Sample REXX Script */
say "Hello, welcome to REXX automation!"
exit
  • say prints output to the screen.
  • exit terminates the script.

Running a REXX Script

To run a script, save it as myscript.rexx and execute it using:

  • On z/OS (mainframe): exec myscript
  • On Windows (Regina REXX Interpreter): rexx myscript.rexx
  • On Linux (Open Object REXX, ooREXX): rexx myscript.rexx

Automating File Operations in REXX

Here is the Automating File Operations in REXX:

Creating and Writing to a File

To create and write to a file, use lineout function:

/* Write to a file */
fileName = "testfile.txt"
call lineout fileName, "This is the first line of text."
call lineout fileName, "This is the second line of text."
call lineout fileName  /* Closes the file */
say "File created successfully."
exit
  • lineout fileName, "text" writes a line to testfile.txt.
  • Calling lineout without arguments closes the file.

Reading from a File

To read from a file, use linein function:

/* Read from a file */
fileName = "testfile.txt"
line = linein(fileName)  /* Read first line */
say "First line of the file: " line
call linein fileName  /* Close the file */
exit
  • linein(fileName) reads a line from testfile.txt.
  • Closing the file after reading is important.

Appending to a File

To add content without overwriting:

/* Append to a file */
fileName = "testfile.txt"
call lineout fileName, "This is an appended line.", "A"  /* "A" mode appends */
call lineout fileName  /* Close the file */
say "Text appended successfully."
exit
  • "A" mode in lineout ensures new content is appended instead of replacing the file.

Automating System Commands Execution

REXX can execute operating system commands using the ADDRESS instruction.

Executing System Commands

/* Running OS Commands */
say "Checking system date and time..."
ADDRESS SYSTEM "date"
ADDRESS SYSTEM "time"
exit
  • ADDRESS SYSTEM "command" runs shell/system commands.
  • Works on Windows (CMD), Unix/Linux (Shell), and IBM mainframes.

Example: Deleting a File

/* Delete a file */
fileName = "testfile.txt"
ADDRESS SYSTEM "del " fileName  /* Windows */
ADDRESS SYSTEM "rm " fileName  /* Linux */
say "File deleted successfully."
exit

Automating User Input and Decision Making

Below is the Automating User Input and Decision Making:

Taking User Input

/* Get user input */
say "Enter your name:"
parse pull userName
say "Hello, " userName "!"
exit
  • parse pull captures user input.

Conditional Execution (IF-ELSE Statements)

/* Conditional Execution */
say "Enter a number:"
parse pull number
if number > 10 then
   say "The number is greater than 10."
else
   say "The number is 10 or less."
exit
  • if-else statements execute based on conditions.

Looping for Repetitive Tasks

Here is Looping for Repetitive Tasks:

Using DO WHILE Loop

/* Print numbers from 1 to 5 */
count = 1
do while count <= 5
   say "Number: " count
   count = count + 1
end
exit
  • do while loops run while a condition is true.

Using DO UNTIL Loop

/* Loop until a condition is met */
num = 0
do until num = 5
   num = num + 1
   say "Number: " num
end
exit
  • do until loops run until a condition becomes true.

Automating Data Processing

Example below shows Automating Data Processing:

Processing a CSV File

/* Read CSV and process data */
fileName = "data.csv"
do while lines(fileName) > 0
   line = linein(fileName)
   parse var line name "," age "," city
   say "Name:" name " | Age:" age " | City:" city
end
call linein fileName  /* Close file */
exit

Reads CSV data line by line and extracts fields using parse var.

Interfacing REXX with Other Languages

Here is Interfacing REXX with Other Languages:

Calling a Python Script from REXX

/* Execute Python Script */
ADDRESS SYSTEM "python myscript.py"
exit
  • Runs an external Python script from REXX.

Scheduling REXX Scripts for Automation

These are the Scheduling REXX Scripts for Automation:

Using Windows Task Scheduler

  1. Open Task Scheduler
  2. Create a new task
  3. Set the action to run rexx myscript.rexx

Using Cron Jobs (Linux)

  1. Open terminal
  2. Type crontab -e
  3. Add the following to schedule a script every day at 9 AM:
0 9 * * * rexx /path/to/myscript.rexx=

Why do we need to Write Automation Scripts in REXX Programming Language?

REXX is a widely used scripting language known for its simplicity, readability, and powerful automation capabilities. Below are the key reasons why REXX is ideal for writing automation scripts.

1. Easy to Learn and Read

REXX has a simple and natural syntax, making it easy for beginners to learn. The code structure is similar to plain English, which improves readability. Unlike complex programming languages, REXX requires minimal syntax knowledge, reducing the learning curve. This makes it an excellent choice for scripting and automation.

2. Platform Independence

REXX scripts can run on multiple operating systems, including IBM mainframes (z/OS), Windows, Linux, and OS/2. This cross-platform compatibility makes it useful for enterprise automation. Since it works consistently across different environments, users can develop scripts once and deploy them anywhere without major modifications.

3. Powerful String and Data Processing Capabilities

REXX excels in text processing, data parsing, and pattern matching, making it ideal for handling logs, reports, and structured files. It has built-in functions for string manipulation, which simplifies processing text-based data. This makes it useful for tasks like log analysis, data extraction, and report generation.

4. Integration with Other Languages and Systems

REXX can seamlessly interact with other programming languages like Python, C, and Java, allowing it to work in hybrid environments. It can also execute shell commands, call system utilities, and interface with databases. This ability makes REXX an excellent choice for system administration and process automation.

5. Efficient File Handling and I/O Operations

REXX provides built-in commands for reading, writing, and modifying files, making it useful for batch processing and file automation. Whether handling CSV, logs, or large datasets, REXX offers easy-to-use functions like linein, lineout, and stream. This reduces the complexity of managing files and directories.

6. Interactive User Input and Decision Making

With parse pull, REXX allows interactive user input, making it useful for dynamic automation scripts. It supports conditional logic (IF-ELSE) and loops, enabling complex decision-making. This makes it ideal for building interactive scripts, menu-driven applications, and system automation tools.

7. Automation of System Administration Tasks

REXX can execute operating system commands, enabling automation of tasks like file management, system monitoring, job scheduling, and application deployment. It can be integrated with IBM Mainframes, Windows Task Scheduler, and Linux Cron Jobs for scheduled execution. This simplifies IT operations and reduces manual workload.

8. Error Handling and Debugging

REXX provides inbuilt error handling mechanisms, such as signal on error and trace commands, which help debug scripts effectively. These features ensure that automation scripts handle unexpected issues gracefully. This makes it easier to develop reliable and fault-tolerant automation scripts.

9. Extensive Support in Enterprise Environments

REXX is widely used in corporate and mainframe environments, especially in financial, telecom, and government sectors. It is commonly used in IBM z/OS, VM/CMS, and TSO/E for batch processing and job automation. Its long-standing presence in enterprise computing makes it a trusted scripting language.

10. Highly Scalable and Maintainable

REXX scripts are modular, easy to maintain, and scalable, making them suitable for both small automation tasks and large-scale enterprise automation. The structured approach of REXX allows users to break down complex tasks into manageable scripts, improving efficiency and maintainability.

Example of Writing Automation Scripts in REXX Programming Language

REXX (Restructured Extended Executor) is a powerful scripting language used for automation in IBM mainframes, Windows, Linux, and other environments. It is widely used for text processing, system automation, and job control.

Automation in REXX involves writing scripts that perform repetitive tasks without human intervention. These scripts can handle file management, data processing, system monitoring, user input handling, and external program execution.

Automating File Creation and Writing Data in REXX

Scenario: Suppose we need to generate a report file and write some data into it. This script automates the file creation and writing process.

REXX Script:

/* Create and Write Data to a File */
fileName = "report.txt"  /* Define the file name */

/* Write content to the file */
call lineout fileName, "Automation Report Generated:"
call lineout fileName, "-------------------------------"
call lineout fileName, "Task: File Creation"
call lineout fileName, "Status: Successful"
call lineout fileName  /* Closes the file */

say "Report file '" fileName "' has been created successfully!"
exit
  • fileName = "report.txt" → Defines the output file name.
  • lineout fileName, "..." → Writes text to the file.
  • call lineout fileName (without parameters) → Closes the file.
  • say → Displays a message on the screen.
Automation Benefit:
  • Reduces manual effort in creating structured reports.
  • Ensures consistency in file creation.

Automating File Reading in REXX

Scenario: We have a log file, and we need to read its content automatically.

REXX Script:

/* Read and Display File Content */
fileName = "report.txt"  /* File to read */

if lines(fileName) = 0 then do
   say "Error: The file is empty or does not exist!"
   exit
end

do while lines(fileName) > 0
   line = linein(fileName)
   say "Read Line: " line
end

call linein fileName  /* Close the file */
exit
  • lines(fileName) → Checks if the file has content.
  • linein(fileName) → Reads each line from the file.
  • do while → Loops through all lines in the file.
  • call linein fileName → Closes the file after reading.

Automation Benefit: Useful for log analysis and batch data processing.

Automating System Commands Execution in REXX

Scenario: A user needs to check the system date, time, and list of files automatically.

REXX Script:

/* Execute System Commands */
say "Fetching system details..."
ADDRESS SYSTEM "date"  /* Fetch current date */
ADDRESS SYSTEM "time"  /* Fetch current time */
ADDRESS SYSTEM "dir"   /* List files (Windows) */
ADDRESS SYSTEM "ls -l" /* List files (Linux) */
exit
  • ADDRESS SYSTEM → Executes OS commands from REXX.
  • "date" → Fetches the current date.
  • "time" → Fetches the current time.
  • "dir" (Windows) and "ls -l" (Linux) → Lists files.
Automation Benefit:
  • Automates system monitoring tasks.
  • Reduces manual effort in checking system details.

Automating User Input Processing in REXX

Scenario: We want to collect user input and display a customized message.

REXX Script:

/* Get User Input */
say "Enter your name:"
parse pull userName  /* Read user input */
say "Hello, " userName "! Welcome to REXX automation."
exit
  • parse pull → Reads user input from the console.
  • say → Displays a personalized message.
Automation Benefit:
  • Useful for interactive automation scripts.
  • Enables user-driven automation processes.

Automating File Deletion in REXX

Scenario: We need to delete a specific file automatically.

REXX Script:

/* Delete a File */
fileName = "old_report.txt"

if stream(fileName, "C", "QUERY EXISTS") = "" then do
   say "Error: File '" fileName "' does not exist!"
   exit
end

say "Deleting file: " fileName
ADDRESS SYSTEM "del " fileName  /* Windows */
ADDRESS SYSTEM "rm " fileName  /* Linux */
say "File deleted successfully."
exit
  • stream(fileName, "C", "QUERY EXISTS") → Checks if the file exists.
  • ADDRESS SYSTEM "del" (Windows) and "rm" (Linux) → Deletes the file.

Automation Benefit: Helps clean up old files automatically.

Automating Data Processing from a CSV File in REXX

Scenario: We need to read and process a CSV file containing names, ages, and cities.

Sample data.csv File:

John,25,New York
Alice,30,London
Bob,22,Tokyo

REXX Script:

/* Read and Process CSV File */
fileName = "data.csv"

if stream(fileName, "C", "QUERY EXISTS") = "" then do
   say "Error: File '" fileName "' does not exist!"
   exit
end

do while lines(fileName) > 0
   line = linein(fileName)
   parse var line name "," age "," city
   say "Name: " name ", Age: " age ", City: " city
end

call linein fileName  /* Close the file */
exit
  • linein(fileName) → Reads a line from the file.
  • parse var → Splits the line using , as a separator.

Automation Benefit: Automates structured data extraction.

Automating Execution of External Scripts in REXX

Scenario: We need to execute a Python script from REXX.

REXX Script:

/* Call External Python Script */
ADDRESS SYSTEM "python process_data.py"
exit

Automation Benefit: Enables cross-language automation.

Automating Scheduled Execution (Task Scheduler & Cron Jobs)

  • Windows Task Scheduler:
    • Open Task Scheduler.
    • Create a new task.
    • Add a trigger to run at a specific time.
    • Set the action to "rexx myscript.rexx".

Linux Cron Job: Add this line to the crontab (crontab -e):

0 9 * * * rexx /path/to/myscript.rexx  # Runs daily at 9 AM

Automation Benefit: Runs REXX scripts automatically at scheduled intervals.

Advantages of Writing Automation Scripts in REXX Programming Language

Here are the advantages of writing automation scripts in REXX programming language:

  1. Simple and Easy-to-Learn Syntax: REXX has an English-like, structured syntax that is easy to understand, reducing the learning curve for beginners and making automation script development faster.
  2. Powerful String Manipulation Capabilities: REXX provides robust built-in string handling functions, making it ideal for text processing, log analysis, and data formatting in automation tasks.
  3. Seamless Integration with Mainframe Systems: REXX interacts effortlessly with IBM mainframe environments, including TSO, ISPF, and JCL, allowing automation of system operations without complex configurations.
  4. Cross-Platform Compatibility: Although primarily used on mainframes, REXX scripts can also run on Windows, Linux, and Unix systems, making it a versatile language for automation across different environments.
  5. Efficient Job Automation in Batch Processing: REXX scripts can be used to automate batch jobs, reducing manual effort and improving efficiency in executing repetitive mainframe tasks.
  6. Dynamic Execution and Interpretation: As an interpreted language, REXX allows immediate execution of scripts without compilation, enabling quick debugging and rapid development of automation solutions.
  7. Robust Error Handling and Debugging Features: REXX provides built-in error handling (e.g., SIGNAL ON ERROR) that helps automate fault detection and correction, ensuring stability in automated processes.
  8. Integration with External Commands and Programs: REXX supports calling external programs, interacting with databases, and executing system commands, allowing automation of complex workflows across different applications.
  9. Reduces Dependency on Complex Scripting Languages: Compared to languages like JCL or Assembler, REXX offers a more user-friendly approach to automation while maintaining powerful scripting capabilities.
  10. Strong Support for System Administration Tasks: REXX is widely used for automating system monitoring, file management, performance tuning, and network operations, making it an essential tool for mainframe administrators.

Disadvantages of Writing Automation Scripts in REXX Programming Language

Here are the disadvantages of writing automation scripts in REXX programming language:

  1. Limited Adoption in Modern IT Environments: REXX is primarily used in mainframe environments, and its adoption in modern automation frameworks like DevOps, cloud computing, and containerized systems is minimal.
  2. Slower Execution Compared to Compiled Languages: Since REXX is an interpreted language, it executes slower than compiled languages like C, Java, or even Python, making it less suitable for high-performance automation tasks.
  3. Lack of Advanced Programming Features: REXX does not support object-oriented programming (OOP), multithreading, or advanced data structures, limiting its ability to handle complex automation scenarios.
  4. Limited Built-in Support for Modern Technologies: Unlike Python or PowerShell, REXX lacks built-in libraries for working with web services, REST APIs, JSON, and cloud platforms, making integration with modern automation tools more difficult.
  5. Dependency on Mainframe Systems: Many REXX scripts rely on IBM-specific tools such as TSO, ISPF, and JCL, making them less portable and difficult to migrate to non-mainframe environments.
  6. Weak Community Support and Fewer Learning Resources: Compared to widely used scripting languages like Python or Bash, REXX has a smaller community, making it harder to find tutorials, forums, and updated documentation.
  7. Limited Compatibility with DevOps and CI/CD Pipelines: REXX does not natively support modern DevOps automation tools like Jenkins, Ansible, or Kubernetes, reducing its effectiveness in modern software development environments.
  8. Difficult to Maintain Large-Scale Scripts: While REXX is great for small automation tasks, maintaining large and complex scripts can be challenging due to the lack of modular programming features.
  9. Not Designed for GUI-Based Automation: REXX is primarily a command-line scripting language and lacks native support for developing graphical user interfaces (GUIs) for automation applications.
  10. Declining Industry Demand: With many companies migrating away from mainframes, the demand for REXX-based automation is decreasing, making it a less future-proof choice for new automation projects.

Future Development and Enhancement of Writing Automation Scripts in REXX Programming Language

Here are the future developments and enhancements that could improve the relevance of writing automation scripts in REXX programming language:

  1. Integration with Cloud Computing Platforms: Enhancing REXX with built-in support for AWS, Azure, and Google Cloud would allow automation scripts to interact with cloud services, making it more useful in hybrid IT environments.
  2. Support for REST APIs and Web Services: Adding native support for RESTful APIs, JSON parsing, and HTTP requests would enable REXX automation scripts to communicate with modern applications, databases, and cloud-based services.
  3. Enhanced Performance with JIT Compilation: Implementing a Just-In-Time (JIT) compiler or optimizing REXX’s execution engine would improve script performance, making it more competitive with compiled languages for automation tasks.
  4. Multithreading and Parallel Processing Capabilities: Introducing multithreading and parallel execution features would allow REXX scripts to handle large-scale automation processes more efficiently, reducing execution time.
  5. Improved Integration with DevOps Tools: Enhancing REXX with native support for Jenkins, Ansible, Kubernetes, and Terraform would make it more relevant for modern CI/CD pipelines and infrastructure automation.
  6. Extended Database Connectivity: Strengthening REXX’s ability to interact with modern databases like PostgreSQL, MySQL, and NoSQL databases (MongoDB, Cassandra) would make it more useful for database automation tasks.
  7. Graphical User Interface (GUI) Development Support: Introducing GUI development libraries would allow REXX scripts to create interactive automation tools, improving usability for non-technical users.
  8. Modern Security Enhancements: Adding support for secure authentication (OAuth, JWT), encryption, and role-based access control (RBAC) would make REXX scripts safer for automating sensitive operations.
  9. Standardization for Cross-Platform Compatibility: Developing standardized extensions that make REXX scripts more portable across mainframes, Windows, Linux, and cloud environments would improve adoption in non-mainframe systems.
  10. Revitalized Documentation and Community Engagement: Expanding learning resources, creating modern tutorials, and increasing community support through forums, GitHub projects, and online courses would encourage more developers to use REXX for automation.

Discover more from PiEmbSysTech

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from PiEmbSysTech

Subscribe now to keep reading and get access to the full archive.

Continue reading