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 firstname.lastname@example.org:/export/home/abc/$( ls -tr _abcde.txt | tail -1 ) /u01/abc/defg/
I also received an error with this line:
ssh email@example.com "scp /export/home/abc/$( ls -tr *_abcde.txt | tail -1 ) /u01/abc/defg/"
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 firstname.lastname@example.org ls -tr /export/home/abc/*_abcde.txt | tail -1 )
scp email@example.com:$newest /u01/abc/defg/