0

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?

punsoca
  • 459
  • 1
  • 7
  • 15
  • 1
    I would try to run a test with same conditions but with a source path/filename that has no spaces. Make sure that works, because your Control-M problem may be something not related to a space char in the path. Also, using `'Excel\ Data'` Is overkill, and in certain cases can create a file (dir) that includes the `"\"` char. I would use dbl-quotes around the complete source file/path name, i.e. `"/storage/data/files/Excel Docs/file1.xlsx"` . Yes there are cases where breaking up a string between quoted and unquoted make sense, but try this. Good luck. – shellter Mar 01 '23 at 03:48
  • @shellter I did test with a file path with no spaces and it worked for Control-M-triggered scripts. – punsoca Mar 01 '23 at 05:50

0 Answers0