I have a bash shell script that runs via cron. The script looks for 1 of 6 possible (data) files in a directory. If 1 or more of these files is found, a new (control) file is created for each data file found. The control file created here is associated (paired) to the data file found, by name, on a 1to1 basis. The main shell script works fine and calls the .exp script (shown below).
spawn sftp "$env(LOGINstring):/inbound/ach"
set timeout 7200
send "put $env(dataFILE)\n"
send "put $env(controlFILE)\n"
send "exit\n"
interact
Here is the data from the process log file.
Calling expect script to transmit the Welfare files...
spawn sftp [email protected]:/inbound/ach
Connected to remote-sftp-server.com.
Changing to: /inbound/ach
sftp> put NEI006AHB08659_WELF
Uploading NEI006AHB08659_WELF to /inbound/ach/NEI006AHB08659_WELF
NEI006AHB08659_WELF 0% 0 0.0KB/s --:-- ETA
NEI006AHB08659_WELF 100% 1710 79.6KB/s 00:00
sftp> put NEI007CTB08659_WELF
exit
Uploading NEI007CTB08659_WELF to /inbound/ach/NEI007CTB08659_WELF
Returned from expect script...
As you can see in the image, the "put" command for the data file (with 006AH) was executed and the data file was transmitted. Then the "put" command for the control file (with 007CT) was executed (or at least enough to display), but the .exp script's "exit" seems to have executed BEFORE the "put" command actually finished.
Thanks in advance!
scp
commands?expect
. Readman expect
and await the prompt fromsftp
(using theexpect
subcommand), rather than blasting the commands, AND sendingsftp
aSIGHUP
signal (man 7 signal
) whenexpect
suddenly exits. I agree with @RomeoNinov -scp
is the better tool.