Hi Scott,

I had suspected that the return value was from the expect command. I have
located a web page of Tcl commands. Not sure how to get the return value back
to a CL program.

I had thought sftp was running asynchronously as it was a spawned process. Not
the same as a forked process, but still a different process.

One thought I had was for the status of the sftp command to be placed in an
environment variable to be tested by the CL program. Odd, but I don't see a CL
command to retrieve the value of an environment variable for testing. What I
did years ago in scripts was put a command within an exit(). I thought that
might work here, but I don't see how to do that with the spawn function being
involved. And I would still need to get the value back to the calling CL. Is
this possible?

John McKee

Quoting Scott Klement <midrange-l@xxxxxxxxxxxxxxxx>:

Hi John,

Not sure why you think it's running asynchronously...

You aren't running sftp -- not directly at any rate -- you're running
expect. Your code is checking to see if expect is ending normally NOT
if sftp is ending normally. So if sftp fails, you have nothing to
detect that.

You need to code expect to look for the failed sftp, and then notify the
calling CL of the failure.



John McKee wrote:
Some issues have arisen. I don't know if there is a way to detect them.

A coworker sends huge files, 500M+, every day. Yesterday, the expect script did
not even make it past the password prompt. No file transfer happened. The
expect script ran to the bottom. There was code to retrieve the status of the
last command. But, it was zero, so no error.

Today, same script, different huge data files. Script runs to completion. No
idea if the data files arrived on the remote site. Below is my expect script,
slightly edited to remove actual destination:

#!/bin/sh

build_script() {

cat <<End-of-message
#!/usr/local/bin/expect -f
set timeout 20
spawn sftp -v ${USER}@ftp.xxx.com
expect "Connecting to ftp.xxx.com...\r\n"
expect "password:"
send "${PASSWORD}\n"
expect "sftp>"
send "put ${PUTFILE} \n"
expect "sftp>"
expect "sftp>"
send "put ${PUTFILE2} \n"
expect "sftp>"
send "quit\n"
exit
End-of-message

}

build_script | /usr/local/bin/expect -f -



Is there something there that causes the actual file transfer to occur
asynchronously, thus not allowing the status to be known to the original
caller?

This is the CL that calls the sFTP script:

CALL QP2SHELL PARM('/usr/bin/sh' '-b' +
'/usr/local/bin/xxx.scr')

/* Check for sFTP error */
CALL PGM(QUSRJOBI) PARM(&RCVVAR +
&RCVVARLEN +
'JOBI0600' +
'*' +
' ' )
IF (%BIN(&RCVVAR 109 4) *NE 0) DO

With the inclusion of the '-b', I am guessing that is why the sFTP is running
asynchronously. My guess. This looks like the only thing that is checked is
whether some part of QP2SHELL has completed, but not the entire script. Is
there some way to pause the CL until the underlying QP2SHELL has completed?

John McKee


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.






As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.