我用这一行将静态HTML文件rsync到我们的网络服务器:
rsync -rlpcgoDvz --delete _site/* x@xx.de:/var/www/x/public/
为了预热网络服务器的缓存,我想在我发布之后立即获取同步文件。使用wget http://www.xx.de/bla/foo.html
或curl
。
有没有办法告诉rsync
或bash
shell这样做?
答案 0 :(得分:0)
我想,你可以用几种方式做到这一点。一个我想出来的:
第1步:
向rsync添加--log-file
选项,以便获取最终采取的操作日志。例如:
rsync -rlpcgoDvz --log-file=log --delete _site/* x@xx.de:/var/www/x/public/
此日志看起来就像那样(例如,日志用于传输4个文件,名为"文件1","文件2","文件3",&#34 ; file4将&#34):
2015/02/13 12:52:11 [54686] receiving file list
2015/02/13 12:52:11 [54686] >f+++++++ file1
2015/02/13 12:52:11 [54686] >f+++++++ file2
2015/02/13 12:52:11 [54686] >f+++++++ file3
2015/02/13 12:52:11 [54686] >f+++++++ file4
我们对>f+++++++
字段感兴趣,下一个字段是文件名。 See this answer简要说明了这里会发生什么。
第2步:
传输完成后,选择文件名并在每个文件名上调用wget
:
cat log | grep ">f++++++" | cut -d \ -f 5 | while read -r filename; do wget "http://www.xx.de/$filename"; done
一块一块地打破它:
cat log | \ # Pipe the file
grep ">f++++++" | \ # Take only interesting lines.
# Here - only files which were not present
# on the other end.
cut -d \ -f 5 | \ # Take the file name.
while read -r filename; do wget "http://www.xx.de/$filename"; done
您可能需要调整一些文件路径等以适合您的使用案例。