1 Reply Latest reply: Apr 15, 2013 2:36 PM by Alan.S-Oracle RSS

    How to cp the latest file from a remote server?

    watson2011
      Hi,

      I want to cp the latest[ls -tr *abc_File | tail 01] file from a remote server. What is the best way to do this? Thank you.

      I got an error, 'No such file or directory' from below line:
      scp user@123.45.67.89:/export/home/abc/$( ls -tr _abcde.txt | tail -1 ) /u01/abc/defg/

      I also received an error with this line:
      ssh user@123.45.67.89 "scp /export/home/abc/$( ls -tr *_abcde.txt | tail -1 ) /u01/abc/defg/"
        • 1. Re: How to cp the latest file from a remote server?
          Alan.S-Oracle
          The shell command substitution you are trying to perform is executed on the local sytem: $(ls -ltr ...). If you want to execute the command on the remote system, then scp cannot do this. You would have to use something like ssh to the remote machine, and execute scp from there. I would recommend a two-part shell script:


          newest=$(ssh user@123.45.67.89 ls -tr /export/home/abc/*_abcde.txt | tail -1 )
          scp user@123.45.67.89:$newest /u01/abc/defg/

          -- Alan