0 pts.
 How can I determine if the SMTP server is active from a CL program?
CLP
In a CL program, I want to start the SMTP server using the command STRTCPSVR *SMTP if it is not already started (such as being auto-started at IPL time). I then intend to end the server at the bottom of the CL, but only if the CL program actually started it. I tried issuing the STRTCPSVR *SMTP command, then monitoring for message TCP3381, "Command attempted while SMTP jobs active". That didn't work because TCP3381 is a *DIAG message, which can't be monitored for. Is there an easy (or at least straightforward) way to determine in a CL program if SMTP is active? Here is a code snippet that I am trying to use. DCL VAR(&SMTPON ) TYPE(*CHAR) LEN( 3) VALUE('NO ') | Other code MONMSG MSGID(CPF9999) EXEC(GOTO CMDLBL(STDERR1)) | STRTCPSVR *SMTP MONMSG MSGID(TCP3381) EXEC(GOTO CMDLBL(NEXT)) CHGVAR VAR(&SMTPON) VALUE('YES') | NEXT: | More code IF COND( &SMTPON = 'YES') THEN(DO) CHGVAR VAR(&SMTPON) VALUE('NO ') ENDTCPSVR *SMTP MONMSG MSGID(CPF9999) ENDDO ENDPGM My main reason I'm trying to do it this way is so I don't end the SMTP server if it was already started when my program runs. Thanks in advance for any help.

Software/Hardware used:
ASKED: September 28, 2006  5:14 PM
UPDATED: October 3, 2006  4:46 AM
  Help
 Approved Answer - Chosen by TomLiotta

Look at it the other way around.
Instead of checking "Command attempted while SMTP jobs active", look for "TCP1A0F - SMTP server starting.".
Both those messages can not be monitored using MONMSG but the "TCP1A0F - SMTP server starting." can be captured by the RCVMSG:
DCL VAR(&MSGID) TYPE(*CHAR) LEN(07)

STRTCPSVR *SMTP
RCVMSG MSGTYPE(*LAST) RMV(*NO) MSGID(&MSGID)
IF (&MSGID *EQ 'TCP1A0F') +
CHGVAR VAR(&SMTPON) VALUE('YES')

ANSWERED:  Oct 3, 2006  4:46 AM (GMT)  by TomLiotta

 
Other Answers:

Hi

You can do this using a CL routine that scans through the active jobs for user QTCP. If job QTSMTPSRVD is active then the SMTP server is running.

The following CL program can be called passing a 10 character return parameter. The parameter will contain *ACTIVE or *INACTIVE when it returns to the calling program:

*************** Beginning of data *********************************
PGM PARM(&RETURN)

DCL VAR(&RETURN) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)

DCLF FILE(QTEMP/SPLF132)

/* First, assume it’s inactive… */
CHGVAR VAR(&RETURN) VALUE(‘*INACTIVE’)

/* Generate a list of all QTCP jobs running in batch… */
WRKUSRJOB USER(QTCP) STATUS(*ACTIVE) OUTPUT(*PRINT) +
JOBTYPE(*BATCH)

/* Copy the spoolfile to a database file in QTEMP… */
CRTPF FILE(QTEMP/SPLF132) RCDLEN(132)
MONMSG MSGID(CPF0000)

CPYSPLF FILE(QPDSPSBJ) TOFILE(QTEMP/SPLF132) +
SPLNBR(*LAST)

/* Read through the file until either the SMTP server job is found or the end */
/* of the file is reached… */

READ: RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM))
IF COND(%SST(&SPLF132 4 10) *NE ‘QTSMTPSRVD’) +
THEN(GOTO CMDLBL(READ))

/* Job active, so set return value… */
CHGVAR VAR(&RETURN) VALUE(‘*ACTIVE’)

/* End the program… */
ENDPGM: ENDPGM

Before compiling the program, issue the command:

CRTPF QTEMP/SPLF132 RCDLEN(132)

and then compile the program interactively.

Hope it helps

All the best

Jonathan

Last Wiki Answer Submitted:  September 29, 2006  8:07 am  by  astradyne   370 pts.
Latest Answer Wiki Contributors:  astradyne   370 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _