I found a PowerPoint presentation you did titled ''Scripting the OpenSSH, SFTP, and SCP Utilities on i''. As my guide I used the sample CL program from the ''Running Expect from a CL Program'' section. Here is my program with the user name, host name and password x'ed out. I have included the corresponding script and the expect log as well.
PGM
DCL VAR(&USER) TYPE(*CHAR) LEN(17) +
VALUE('accountxxxxxxxxxx')
DCL VAR(&PASS) TYPE(*CHAR) LEN(5) VALUE('xxxxx')
DCL VAR(&HOST) TYPE(*CHAR) LEN(12) +
VALUE('xxxx.xxxx.xx')
DCL VAR(&CMD) TYPE(*CHAR) LEN(500)
CHGVAR VAR(&CMD) +
VALUE('PATH=$PATH:/Qopensys/usr/bin:/usr/lo+
cal/bin && expect -f myscript.exp')
ADDENVVAR ENVVAR(SSH_USER) VALUE(&USER) REPLACE(*YES)
ADDENVVAR ENVVAR(SSH_HOST) VALUE(&HOST) REPLACE(*YES)
ADDENVVAR ENVVAR(SSH_PASS) VALUE(&PASS) REPLACE(*YES)
ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) +
VALUE('FILE=/tmp/expect.log') REPLACE(*YES)
ADDENVVAR ENVVAR(QIBM_QSH_CMD_ESCAPE) +
VALUE('Y') REPLACE(*YES)
QSH CMD(&CMD)
MONMSG MSGID(QSH0000) EXEC(DO)
SNDMSG MSG('File Transfer failed! See +
/tmp.expect.log') TOUSR(ROBERT)
ENDDO
ENDPGM
Here is the corresponding script. I hardcoded the user and host but plan to use the environment variables once I get the file transfer to work.
#!/usr/local/bin/expect -f
set timeout 20
spawn sftp accountxxxxxxxxxxx@xxxx.xxxx.xx
expect {
default {exit 2}
"continue connecting yes/no?" {send "yes\n"; exp_continue}
"assword:" {send "$env(ssh_pass)\n"; exp_continue}
"sftp>"
}
send "cd /out\n"
expect {
default {exit 3}
"sftp> "
}
send "get purchase*\n"
expect "{
default exit 4
"sftp>"
}"
send "quit\n"
exit 0
And the results in my error log.
Browse : /tmp/expect.log
Record : 1 of 4 by 14 Column : 1 68 by 79
Control :
....+....1....+....2....+....3....+....4....+....5 ....+....6....+....7....+....
************Beginning of data**************
invalid command name "@{Za¤¢ a     a   a §   £@` "
while executing
"@{Za¤¢ a     a   a §   £@` "
(file "myscript.exp" line 1)
************End of Data********************
PGM
DCL VAR(&USER) TYPE(*CHAR) LEN(17) +
VALUE('accountxxxxxxxxxx')
DCL VAR(&PASS) TYPE(*CHAR) LEN(5) VALUE('xxxxx')
DCL VAR(&HOST) TYPE(*CHAR) LEN(12) +
VALUE('xxxx.xxxx.xx')
DCL VAR(&CMD) TYPE(*CHAR) LEN(500)
CHGVAR VAR(&CMD) +
VALUE('PATH=$PATH:/Qopensys/usr/bin:/usr/lo+
cal/bin && expect -f myscript.exp')
ADDENVVAR ENVVAR(SSH_USER) VALUE(&USER) REPLACE(*YES)
ADDENVVAR ENVVAR(SSH_HOST) VALUE(&HOST) REPLACE(*YES)
ADDENVVAR ENVVAR(SSH_PASS) VALUE(&PASS) REPLACE(*YES)
ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) +
VALUE('FILE=/tmp/expect.log') REPLACE(*YES)
ADDENVVAR ENVVAR(QIBM_QSH_CMD_ESCAPE) +
VALUE('Y') REPLACE(*YES)
QSH CMD(&CMD)
MONMSG MSGID(QSH0000) EXEC(DO)
SNDMSG MSG('File Transfer failed! See +
/tmp.expect.log') TOUSR(ROBERT)
ENDDO
ENDPGM
Here is the corresponding script. I hardcoded the user and host but plan to use the environment variables once I get the file transfer to work.
#!/usr/local/bin/expect -f
set timeout 20
spawn sftp accountxxxxxxxxxxx@xxxx.xxxx.xx
expect {
default {exit 2}
"continue connecting yes/no?" {send "yes\n"; exp_continue}
"assword:" {send "$env(ssh_pass)\n"; exp_continue}
"sftp>"
}
send "cd /out\n"
expect {
default {exit 3}
"sftp> "
}
send "get purchase*\n"
expect "{
default exit 4
"sftp>"
}"
send "quit\n"
exit 0
And the results in my error log.
Browse : /tmp/expect.log
Record : 1 of 4 by 14 Column : 1 68 by 79
Control :
....+....1....+....2....+....3....+....4....+....5 ....+....6....+....7....+....
************Beginning of data**************
invalid command name "@{Za¤¢ a     a   a §   £@` "
while executing
"@{Za¤¢ a     a   a §   £@` "
(file "myscript.exp" line 1)
************End of Data********************
Comment