我想将文件从远程服务器复制到本地服务器。问题是:我只想复制昨天的文件。 远程服务器正在写日志文件,在23:59,logrotation将其压缩为文件[name] _ [date] .log.gz。早上6点,本地服务器上的cronjob需要复制先前从远程服务器创建的文件。有谁知道怎么做?
此致 亚历
答案 0 :(得分:10)
您可以使用这样的脚本
for i in `find /interface/outbound/Web -type f -ctime -1`
do
scp $i user@$destination_server:/destination_directory/
done
特别是命令find as as features features例如:
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
中的更多信息
修改强>
要从远程到本地具有相同的行为,您可以使用以下内容:
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环境可以进行一些测试。