开发者

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

开发者 https://www.devze.com 2023-01-23 14:12 出处:网络
Ok so I kinda know how to do this locally with a find t开发者_JAVA技巧hen cp command, but don\'t know how to do the same remotely with scp.

Ok so I kinda know how to do this locally with a find t开发者_JAVA技巧hen 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?


remote_dir=/what/ever
dst=remote-system.host.name.com
scp $dst:`ssh $dst ls -1td $remote_dir/\* | head -1` /tmp/lastmod


Write a script on the remote side that uses find to find it and then cat to send it to stdout, then run:

ssh me@server runscript.sh > localcopy
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号