Automate IBM i green-screen tasks: job scheduler, SBMJOB, SSH and screen scripts
Ways to automate work you now type on an IBM i 5250 screen: a CL command in the job scheduler, SBMJOB, the PASE system command over SSH, or a screen script.
If you do the same thing on an IBM i screen every day, you may be able to have the system do it. Pick the method by what the task is.
The task is a CL command or program: schedule it
First find the CL command or program behind the task: press F4 on a command to see its parameters, or ask the developer which program a menu option calls. Once you have a command, the job scheduler can run it for you:
ADDJOBSCDE JOB(CLEANUP) CMD(CALL PGM(CLNUPLIB/CLNUPPGM)) +
FRQ(*WEEKLY) SCDDATE(*NONE) SCDDAY(*FRI) SCDTIME('23:00:00') +
RCYACN(*NOSBM) JOBD(CLNUPLIB/CLNUPJOBD)
This is IBM's example: it submits a batch job named CLEANUP every Friday at 11 p.m. With RCYACN(*NOSBM), a run missed because the system was down or restricted is not submitted later. The entry holds everything needed to submit the job: the command, the job description, the user profile, the job queue and the message queue. IBM notes that the job is submitted at that time, but it does not start if the job queue is held or not attached to an active subsystem, or if the maximum number of active jobs has been reached. WRKJOBSCDE shows the entries; CHGJOBSCDE, HLDJOBSCDE, RLSJOBSCDE and RMVJOBSCDE change, hold, release and remove them.
Run it now, but not on your screen: SBMJOB
SBMJOB sends a command to a job queue to run as a batch job, so your interactive session is free while it runs:
SBMJOB CMD(CALL PGM(MYLIB/NIGHTLY)) JOB(NIGHTLY)
Its output goes to spooled files and its messages to the job log, not to your screen. See Save an IBM i spooled file as a PDF: CPYSPLF WSCST(*PDF) and Navigator for getting a report out.
Drive it from another computer: SSH and the system command
If SSH is running on the IBM i, a script on another computer can log in and run CL commands with the PASE system utility:
ssh [email protected] 'system "DSPLIB MYLIB"'
Spooled output from the command is written to standard output. If the command sends an exception message, system exits with status 255, so the calling script can check for failure. Quote the CL command, because the shell would otherwise expand parentheses and asterisks. See IBM i SSH "Permission denied": home, key permissions, PASE shell if the login fails.
Only the screen will do: a screen script
Some tasks exist only as screens: a vendor application with no command behind it, for example. Then the choice is an emulator script that types into the screen and waits for the next one. Scripts break when the screen layout changes, so use them only when there is no command or API. For the 3270 side of this, see Automate a 3270 session from a script: s3270, Wait and screen scraping.
Related
- IBM i CL basics
- IBM i equivalent of sudo: SBMJOB USER, adopted authority and profile swaps
- IBM i sessions explained: display device, interactive job and sign-on
- Automate a 3270 session from a script: s3270, Wait and screen scraping
- IBM i job log missing or empty: CHGJOB LOG, LOGCLPGM and pending job logs
- Run SQL on IBM i from a 5250 session: STRSQL, RUNSQL and RUNSQLSTM
- App guide: Scripts and macros