I'm writing a shell script to automate the task of extracting data from a remote oracle database and temporarily storing it in the local machine in a folder say Csvfoder. I used 'expect' command to copy all files in this Csvfolder to the ftp server.
These csv files in the Csvfolder have specific names( In the below example timestamp has two system timestamps joined) -
For example, data extracted from oracle Table1 will have the name ABCD.(timestamp1).csv, after the script runs again after 15 mins, the Csvfolder might have another file extracted from oracle Table1 will have the name ABCD.(timestamp2).csv
Data extracted from oracle Table2 will have the name, say XYZ.(timestamp10).csv, after the script runs again after 15 mins, the Csvfolder might have another file extracted from oracle Table2 will have the name XYZ.(timestamp11).csv
Right now my script just uploads all the *.csv files in Csvfolder to the FTP server using expect.
But I have a mapping of csv file names to some specific directories on the FTP server that the csv file should go to-
From the above example, I want all ABCD.(timestampxx).csv files to be copied from my local machine to the FTP folder HOME_FOLDER/FOLDER_NAME1 (unique folder name). I want all XYZ.(timestamp).csv files to be copied from my local machine to the FTP folder HOME_FOLDER/FOLDER_NAME2 (unique folder name). In this example I will have the mapping:
ABCD files -> should go to HOME_FOLDER/FOLDER_NAME1 of FTP server
XYZ files -> should go to HOME_FOLDER/FOLDER_NAME2 of FTP server
I'm using expect with mput in my shell script right now:
expect -c '
set username harry
set ip 100.132.123.44
set password sally
set directory /home/harry
set csvfilesFolder /Csvfolder/
spawn sftp $username@$ip
#Password
expect "*password:"
send "$password\n"
expect "sftp>"
#Enter the directory you want to transfer the files to
send "cd $directory\n"
expect "sftp>"
send -r "mput $csvfilesFolder*\n"
expect "sftp>"
send "exit\n"
interact'
Any suggestions as how to go about coping those csv files from local machine to specific directories on FTP server using the mapping?