Automating PWDEXPMON with the SETUP_SCHEDULE CL Program
As we wrap up our dive into the PWDEXPMON suite for password expiration monitoring, let's look at the SETUP_SCHEDULE CL program. This handy script automates the whole thing by adding job schedule entries to run your monitor daily. If you've been following along, this ties everything together, turning your manual tool into a set-it-and-forget-it admin helper. We'll keep it technical, focused on IBM i job scheduling, and walk through the code step by step.
How SCHEDULE Works
This CL program automates the setup of a password expiration monitoring job on IBM i by configuring the job scheduler.
Core Functionality
Purpose: Creates a scheduled job that runs the password expiration monitor (PWDEXPMON) daily at 8:00 AM to check for passwords expiring within 7 days.
Execution Flow
Error Monitoring (line 72)
- Sets up global error handler using
MONMSGfor all CPF messages - Redirects errors to ERROR label for centralized handling
- Sets up global error handler using
Remove Existing Schedule (lines 77-78)
- Uses
RMVJOBSCDEto delete any existing PWDEXPMON schedule - Suppresses CPF1304 error (schedule not found) to allow clean first-time execution
- Uses
Create New Schedule (lines 84-91)
ADDJOBSCDEcreates the job schedule entry:- Job name: PWDEXPMON
- Command: Runs PWDEXPMON with PERIOD(*WEEK) parameter
- Frequency: Weekly (
FRQ(*WEEKLY)) - Days: Every day (
SCDDAY(*ALL)) - Time: 8:00 AM (
SCDTIME('080000')) - Save: Preserved across IPLs (
SAVE(*YES))
User Notification (lines 93-100)
- Sends completion message confirming successful scheduling
- Provides guidance to use
WRKJOBSCDEfor schedule management
Error Handling (lines 107-112)
- Captures exception details using
RCVMSG - Sends escape message with error ID and description
- Captures exception details using
Key Design Features
- Idempotent: Can be run multiple times safely (removes before creating)
- Library-independent: Uses current library context
- Production-ready: Comprehensive error handling and user feedback
- Persistent: Schedule survives system restarts (
SAVE(*YES))
Usage
Simply call the program to set up or update the schedule:
CALL SCHEDULE
View or modify schedules afterward:
WRKJOBSCDE/* Program: SCHEDULE - Setup Password Monitor Job Schedule */
/* --------------------------------------------------------------------- */
/* Description: Configures IBM i job scheduler to run password */
/* expiration monitoring automatically. Sets up daily */
/* scheduling for the password expiration monitor to run */
/* at 8:00 AM. Creates two schedules: 7-day warning and */
/* 14-day warning. Can be run multiple times safely as it */
/* removes existing schedules first. */
/* */
/* Purpose: Production utility demonstrating: */
/* - Job scheduler configuration (ADDJOBSCDE) */
/* - Schedule removal and recreation */
/* - Multiple schedule management */
/* - Error handling for schedule operations */
/* - Library-independent scheduling */
/* */
/* Features: */
/* - Creates 7-day warning schedule (8:00 AM daily) */
/* - Creates 14-day warning schedule (8:05 AM daily) */
/* - Removes existing schedules before creating new ones */
/* - Uses current library for program location */
/* - Comprehensive error handling */
/* - Informational messaging */
/* */
/* Usage: */
/* CALL SCHEDULE */
/* */
/* Schedules Created: */
/* - PWDEXPMON: Runs daily at 8:00 AM, checks 7 days ahead */
/* */
/* Prerequisites: */
/* - PWDEXPMON program must exist in current library */
/* - User must have authority to manage job schedules */
/* */
/* Management: */
/* - Use WRKJOBSCDE to view or modify schedules */
/* - Use RMVJOBSCDE to remove schedules */
/* - Re-run this program to update schedule times */
/* */
/* Compiler Options: */
/* CRTBNDCL PGM(library/SCHEDULE) SRCFILE(library/QCLLESRC) */
/* SRCMBR(SCHEDULE) */
/* */
/* Reference: */
/* - IBM i Work Management Guide */
/* - ADDJOBSCDE Command Reference */
/* */
/* Modification History: */
/* V.000 2026-02-03 | Nick Litten | Initial creation */
/* V.001 2026-04-04 | Nick Litten | Standardized header block */
/* V.002 2026-04-18 | Nick Litten | Applied comment standards */
/* V.003 2026-05-28 | Nick Litten | Standardized separator format */
/* V.004 2026-05-28 | Nick Litten | Refreshed Comment header block */
/* --------------------------------------------------------------------- */
PGM
DCLPRCOPT LOG(*NO) DFTACTGRP(*NO) ACTGRP(*CALLER)
COPYRIGHT TEXT('V.004 - Setup Password Monitor Job Schedule')
/* --------------------------------------------------------------------- */
/* Variable declarations */
/* --------------------------------------------------------------------- */
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(256)
/* --------------------------------------------------------------------- */
/* Monitor for errors */
/* --------------------------------------------------------------------- */
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
/* --------------------------------------------------------------------- */
/* Remove existing schedule if it exists */
/* --------------------------------------------------------------------- */
RMVJOBSCDE JOB(PWDEXPMON)
MONMSG MSGID(CPF1304)
/* --------------------------------------------------------------------- */
/* Add new job schedule entry */
/* Runs daily at 8:00 AM, checks for passwords expiring in 7 days */
/* --------------------------------------------------------------------- */
ADDJOBSCDE JOB(PWDEXPMON) +
CMD( PWDEXPMON PERIOD(*WEEK) ) +
FRQ(*WEEKLY) +
SCDDATE(*NONE) +
SCDDAY(*ALL) +
SCDTIME('080000') +
SAVE(*YES) +
TEXT('Password expiration monitor - 7 day warning')
SNDPGMMSG MSG('Password monitor scheduled successfully. Will run +
daily at 8:00 AM.') TOPGMQ(*EXT) MSGTYPE(*COMP)
/* --------------------------------------------------------------------- */
/* Display the schedules */
/* --------------------------------------------------------------------- */
SNDPGMMSG MSG('Use WRKJOBSCDE to view or modify the schedules.') +
TOPGMQ(*EXT) MSGTYPE(*INFO)
GOTO CMDLBL(ENDPGM)
/* --------------------------------------------------------------------- */
/* Error handling */
/* --------------------------------------------------------------------- */
ERROR:
RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('Failed to setup schedule: ' *CAT &MSGID +
*CAT ' - ' *CAT &MSGDTA) MSGTYPE(*ESCAPE)
/* --------------------------------------------------------------------- */
/* Program end */
/* --------------------------------------------------------------------- */
ENDPGM:
ENDPGM
This SETUP_SCHEDULE program rounds out your PWDEXPMON toolkit, making password monitoring a background task on IBM i. If you're implementing this, test in a non-prod environment first. Got your own scheduling tweaks? Share them on the forum. Keep automating, folks!
