您好我想使用AppleScript将文件从源Macserver复制到使用rsync的其他10台Mac服务器。我有基本的工作:
set source to "/Folder1/Folder2/"
mount volume "afp://username:password@server1/Folder1/"
set Folder1 to result as alias
set destShareName to "/Volumes/Folder1/Folder3"
do shell script "/usr/bin/rsync -rlptD --log-file=/Users/user/Documents/rsync.txt " & (quoted form of source) & " " & (quoted form of destShareName)
它有效,我得到了一份工作日志。我知道我可以复制作业并用server2替换server1并再次运行作业。如何创建服务器列表并使rsync作业在列表中重复运行?非常感谢,约翰
答案 0 :(得分:1)
像这样的东西。您制作列表并使用重复循环。第一次通过重复循环,您可以获取列表中的所有第一项,因此请确保每个列表中的所有第一项都在一起。第二次通过你将获取所有第二项,依此类推。请注意,所有列表应具有完全相同的项目数。
set theServers to {"afp://username:password@server1/Folder1/", "afp://username:password@server2/Folder1/"}
set sourceFolders to {"/source1Folder/Folder2/", "/source2Folder/Folder2/"}
set destFolders to {"/dest1Folder/Folder2/", "/dest2Folder/Folder2/"}
repeat with i from 1 to count of sourceFolders
set thisServer to item i of theServers
set thisSource to item i of sourceFolders
set thisDest to item i of destFolders
mount volume thisServer
do shell script "/usr/bin/rsync -rlptD --log-file=/Users/user/Documents/rsync.txt " & (quoted form of thisSource) & " " & (quoted form of thisDest)
end repeat
编辑 :根据您的评论,如果只有您的服务器发生变化,那么您可以像这样调整代码......
set theServers to {"afp://username:password@server1/Folder1/", "afp://username:password@server2/Folder1/"}
set sourceFolder to "/source1Folder/Folder2/"
set destFolder to "/dest1Folder/Folder2/"
repeat with i from 1 to count of theServers
mount volume (item i of theServers)
do shell script "/usr/bin/rsync -rlptD --log-file=/Users/user/Documents/rsync.txt " & (quoted form of sourceFolder) & " " & (quoted form of destFolder)
end repeat