How can I determine if the SMTP server is active from a CL program?

pts.
Tags:
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.

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Ayahel1
    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')
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following