I have a scenario where I am receiving multiple files in a directory and I need to transfer those files received in 60 mins to some other server. So for that I use below command.
{ find -maxdepth 1 -type f -mmin -60| cut -d'/' -f2 | sed 's/^/put /' ; echo bye ; } | \
/usr/local/bin/sshpass -p password sftp -oBatchMode=no username@xx.xxx.xxx.xxx:/folder
Now, I need to modify the command and make a log file where i need to print the filenames of files being transferred. I made below script but somehow not convinced with the script as the logfile is also getting transferred and also running find command twice can result in some data discrepancy as might be by the time log file is getting generated a new file is received and gets transferred. Please suggest how to fix this.
#!/bin/bash
file=/root/test/file_$(date +%Y-%m-%d_%H%M%S)
find -maxdepth 1 -type f -mmin -60| cut -d'/' -f2 > $file
{ find -maxdepth 1 -type f -mmin -60| cut -d'/' -f2 | sed 's/^/put /' ; echo bye ; } | \
/usr/local/bin/sshpass -p password sftp -oBatchMode=no username@xx.xxx.xxx.xxx:/folder