Search code examples
bashshellsshscp

Copy the output of find command with scp


I am trying from a local machine, to daily check what are the new files in the server, then copy them with one scp.

I call the script with ssh bastibast@192.168.0.200 'bash -s' < fileretriever.sh

#!/usr/bin/env bash -x


FILES=$(find /home/bastibast/test -type f -mtime 0 )
echo "'$FILES'"
exit
scp -T -i ~/.ssh/id_rsa bastibast@192.168.0.200:"'$FILES'" ~/test/multiplecopy  

However nothing is copied to my local machine.

Output of echo "'$FILES'": '/home/bastibast/test/test2 /home/bastibast/test/test1 /home/bastibast/test/script'

And when I run scp -T bastibast@192.168.0.200:'/home/bastibast/test/test2 /home/bastibast/test/test1 /home/bastibast/test/script' ~/test/multiplecopy

It works perfectly, the 3 files are copied to my local machine. Why won't it work in the script ?


Solution

  • What I was trying to do could be done way more easily by just extracting the output of the command find into a variable with ssh

    FILES=$(ssh bastibast@192.168.0.200 -- find /home/bastibast/test -type f -mtime 0 2>&1)

    And then scp from there.