Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to scp newest file in a directory on a remote server

Ok so I kinda know how to do this locally with a find then cp command, but don't know how to do the same remotely with scp.

So know this:

scp -vp me@server:/target/location/ /destination/dir/.

That target directory is going to be full of database backups, how can I tell it to find the latest backup, and scp that locally?

like image 683
beatbreaker Avatar asked Feb 03 '23 01:02

beatbreaker


1 Answers

remote_dir=/what/ever
dst=remote-system.host.name.com
scp $dst:`ssh $dst ls -1td $remote_dir/\* | head -1` /tmp/lastmod
like image 57
DigitalRoss Avatar answered Feb 05 '23 17:02

DigitalRoss