I have the following shell script that runs automated scp commands.
copy_prod_files.sh content:
#!/usr/bin/expect
spawn scp ftpaccess@prod:/storage/data/files/'Excel\ Docs'/file1.xlsx /data/prod/
expect "ftpaccess@prod's password:"
send "##########\n"
send "exit\n"
interact
Please note that the source file path /storage/data/files/Excel Docs/file1.xlsx contains a directory name with space (i.e., 'Excel Docs') - I enclosed the directory name in single quotes and I put
a backslash (or escape)
character to denote a space.
When I executed the above script manually it is successful - the file1.xlsx
is copied to the destination folder /data/prod.
$ ./copy_prod_files.sh
spawn scp ftpaccess@prod:/storage/data/files/'Excel Docs'/file1.xlsx /data/prod/
ftpaccess@prod's password:
file1.xlsx 100% 20MB 141.8MB/s 00:00
HOWEVER, WHEN the script is executed by Control-M - the Control-M shows it was successfully ran, but this is what I see when I checked the shell script log:
spawn scp ftpaccess@prod:/storage/data/files/'Excel Docs'/file1.xlsx /data/prod/
ftpaccess@asbi-prod's password:
The log file content only shows the 'spawn scp' command and the password prompt.
I notice that the spawn scp log echoes the "spawn scp" statement "/storage/data/files/'Excel Docs'/file1.xlsx /data/prod/" with the Excel Docs enclosed in single quotes - which is also seen from the manual script run. But for some reason the shell script was able to performed the file transfer while the Control-M-triggered script run does not. It seems to me that when the script is run from Control-M it probably could not find the file path and thus NO file trasnfer occurred? And the Control-M script log result didn't seem to capture any error either.
How do I update my shell script so that when it runs via the Control-M it could detect /storage/data/files/Excel Docs/file1.xlsx /data/prod/ and thus able to transmit the file.xlsx to the destination folder?