我想将文件从远程服务器复制到本地服务器.问题是:我只想复制昨天的文件.
远程服务器正在写日志文件,在23:59,logrotation将其压缩为文件[name] _ [date] .log.gz.早上6点,本地服务器上的cronjob需要复制先前从远程服务器创建的文件.有谁知道如何做到这一点?
问候,
亚历克斯
解决方法:
你可以使用这样的脚本
for i in `find /interface/outbound/Web -type f -ctime -1`
do
scp $i user@$destination_server:/destination_directory/
done
特别是该命令可以找到以下功能,例如:
find . -ctime -1 # which are created less than 1 day ago from currrent folder.
find . -ctime +2 # finds files which are created older than 2 days from currrent folder.
其中ctime是创建时间.也可以这样使用修改时间mtime:
find . -mtime 0 # find files modified between now and 1 day ago
find . -mtime -1 # find files modified less than 1 day ago
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago
更多信息,请参见man find
编辑:
要从远程到本地具有相同的行为,您可以使用以下内容:
latest_file=`ssh user@destination_server find /pathtoDir -type f -ctime -1`
/usr/bin/scp user@destination_server:$latest_file /local_dir
echo SCP Completed.
此刻我还没有Unix环境来进行一些测试.
标签:unix,linux,scp
来源: https://codeday.me/bug/20190718/1492578.html