2016-11-21 2 views
0

У меня есть AppleScript, который используется для копирования файлов (с помощью Rsync) от источника к множеству мест:Applescript не бросить, когда erroring

set Servers to {"afp://service.username:[email protected]/Public/", "afp://service.username:[email protected]/Public/", "afp://service.username:[email protected]/Public/", "afp://service.username:[email protected]/Public/", "afp://service.username:[email protected]/Public/"} 
--these are constant so no need to change 
set Source to "/Shared Items/Public/DeployStudio/Masters/HFS/Sierra.hfs.dmg" 
set Destination to "/Volumes/Public/DeployStudio/Masters/HFS" 
--the scripts that goes recursively through the list of servers 
repeat with i from 1 to count of Servers 
    set thisServer to item i of Servers 
    --this will mount each server destination in turn creating a /Volumes/Public folder 
    mount volume thisServer 
    --these are two rsync scripts which creates logfiles 
    do shell script "/usr/bin/rsync -rlptD --log- file=/Users/username/Documents/logs/Sierra-rsync.log " & (quoted form of Source) & " " & (quoted form of Destination) 
    --not sure this is needed but added this 5 sec delay to stop ejecting disk errors 
    delay 5 
    --eject the mounted volume so we don't have multiple Public folders 
    tell application "Finder" 
     eject disk "Public" 
    end tell 
end repeat 

Это прекрасно работает и производит журнал, что он делает. Если есть проблема. Тогда он просто уйдет. Я хотел бы изменить его, чтобы он игнорировал ошибки и продолжал идти. Есть идеи? Благодаря

ответ

0

Чтобы игнорировать ошибки в цикле повторения оберните пораженный код в try блоке

repeat with i from 1 to count of Servers 
    set thisServer to item i of Servers 
    try 

     ... 

    end try 
end repeat 
+0

приятно. большое спасибо. скажите, вы можете добавить -v или -vv перед -log, чтобы иметь более подробный журнал? Еще раз спасибо –

+0

Я не знаком с rsync, пожалуйста, прочитайте страницу 'man'. – vadian

Смежные вопросы