find error do shell script with rsync command

I've written intentionally a wrong script in order to find the errors.

The output using the rsync command is the following:


Last login : Tue March 4 11:34:59 on console

server: ~ simonepiersigilli $ rsync- avz - progress - stats / Users / simonepiersigilli / Desktop / Test / / Users/simonepiersigilli/Desktop/Test2 / 2 > & 1

building file list ...

rsync: link_stat " / Users / simonepiersigilli / Desktop / Test / . " failed: No such file or directory ( 2 )

0 files to Consider



Number of files: 0

Number of files transferred: 0

Total file size: 0 bytes

Transferred Total file size: 0 bytes

Literal data : 0 bytes

Matched data : 0 bytes

File list size: 13

File list generation time: 0.001 seconds

File list transfer time: 0.000 seconds

Total bytes sent: 29

Total bytes received : 20



sent 29 bytes received 20 bytes 32.67 bytes / sec

total size is 0 speedup is 00:00

rsync error : some files Could not be Transferred (code 23) at / SourceCache/rsync/rsync-42/rsync/main.c ( 992 ) [ sender = 2.6.9 ]

server: ~ $ simonepiersigilli


The output is correct becaus the "test" folder doesn't exist

Following Apple's instruction (https://developer.apple.com/library/mac/technotes/tn2065/_index.html) I've insert 2>&1 at the end of the command, as shown by the following script.


set risultato to 0

try

set risulato to "rsync -avz --progress --stats /Users/simonepiersigilli/Desktop/Test/ /Users/simonepiersigilli/Desktop/Test2/ 2>&1"

end try


display dialogrisultato


The result does not contain neither the error, nor the output:

User uploaded file

How can I use do shell script in order to find the error and the output?

Mac mini, OS X Mavericks (10.9.2)

Posted on Mar 4, 2014 6:21 AM

Reply
6 replies

Mar 4, 2014 1:02 PM in response to cpassociati

You will note that any non zero rc out of do shell script invokes on error.


(*


I

Author: rccharles


For testing, run in the Script Editor.

1) Click on the Event Log tab to see the output from the log statement

2) Click on Run


For running shell commands see:

http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html



It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on. Here is an example.




*)



on run

-- Write a message into the event log.

log " --- Starting on " & ((current date) as string) & " --- "

-- debug lines

set desktopPath to (path to desktop) as string

log "desktopPath = " & desktopPath


set unixDesktopPath to POSIX path of desktopPath

log "unixDesktopPath = " & unixDesktopPath


set quotedUnixDesktopPath to quoted form of unixDesktopPath

log "quoted form is " & quotedUnixDesktopPath


try

set fromUnix to do shell script "ls -l " & quotedUnixDesktopPath

display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix

on error errMsg

log "ls -l error..." & errMsg

end try


end run

Mar 4, 2014 5:29 PM in response to cpassociati

I think rccharles has the answer... rsync returns a result code based on the success (or otherwise) of the command. In this case I think you're likely getting a result code of 23 which indicates 'Partial transfer due to error'. This isn't necessarily indicative of a failure of the entire process, just that specific items could not be synched. It isn't clear from your post whether there were other files that could/should have been synched, or whether they were.


In either case, the simple 'fix' here is to wrap your do shell script in a try/end try block. This will catch the error and prevent the AppleScript from failing.


set rsyncCmd to "/usr/bin/rsync -blah -blah -blah 2>&1"

try

do shell script rsyncCmd

on error

-- do nothing, we don't care (unless you want to examine what happened)

end try

Mar 5, 2014 6:34 AM in response to Camelot

I modified the script like you had said (see "New Applescript"), but the script stops when it bump into the first error. I need a script that is able to find all the errors (see "Using rsync from Terminal" - Variable errMsg), without stopping his work, and display the outputs (Variable "risultato").


New Applescript

try

set risultato to do shell script "rsync -avz --progress --stats /Users/simonepiersigilli/Desktop/Test/ /Users/simonepiersigilli/Desktop/Test2/"


display dialogrisultato

on error errMsg


logerrMsg


display dialogerrMsg

end try


Using rsync from "Terminal"

Error

rsync: chgrp \"/Documenti/Lavori/AGIP-AN-Jesi-Via Gallodoro-57073/Ip7073 Jesi Via Gallo D#239.dwg\" failed: Operation not permitted (1)

rsync: chgrp \"/Documenti/Lavori/AGIP-AP-Piane di Montegiorgio-7323/AGIP 7323 Piane di Montegiorgio NUOVO LAYOUT/AGIP 7323 Piane di Montegiorgio TAV.06 IMPIANTO ACQUE REFLUE.dwg\" failed: Operation not permitted (1)


Output

AGIP-AN-Camerano-SS16-5755/Adeguamento scarichi 2013/Atto Unico Comune di Camerano/POSTA CERTIFICATA- Prot. N.168 del 09-01-2014 - Provvedimento autorizzativo unico per adeguamento impianto fognario ditta ENI Spa SS16/All.03-Autorizz.Idraulica_PROV.AN-19.11.2013.pdf

32768 17% 0.00kB/s 0:00:00

191288 100% 9.45MB/s 0:00:00 (xfer#3, to-check=143383/148734)

AGIP-AN-Camerano-SS16-5755/Adeguamento scarichi 2013/Atto Unico Comune di Camerano/POSTA CERTIFICATA- Prot. N.168 del 09-01-2014 - Provvedimento autorizzativo unico per adeguamento impianto fognario ditta ENI Spa SS16/All.04-Disciplinare_ANAS-AN13-059.pdf

32768 11% 0.00kB/s 0:00:00

285033 100% 551.12kB/s 0:00:00 (xfer#4, to-check=143382/148734)


Thank you

Cesare

Mar 7, 2014 12:31 PM in response to Camelot

Using your instructions, I modified the applescript (see below) and now it works fine.


New Applescript

try

set risultato to do shell script "rsync -avz --stats /Users/cesare/Desktop/Test/ /Users/cesare/Desktop/Test2/"


display dialogrisultato

on error errMsg


logerrMsg


display dialogerrMsg

end try


Can you show me how to show a simple progress bar, changing the applescript above, that shows building file list and the backup file?


Thank you

Cesare

Mar 8, 2014 1:19 AM in response to cpassociati

Can you show me how to show a simple progress bar, changing the applescript above, that shows building file list and the backup file?


There is no 'simple progress bar' option here.


By default, AppleScript is single threaded and will wait for each command to execute before processing the next. This means, ordinarily, that AppleScript will wait for the do shell script command to finish before it would get to the line that displays the progress bar.


There's one exception to this rule, but it's not pretty. It involves executing the shell command in the background and redirecting its logs to a specific file. The AppleScript code following the do shell script command then loops through reading the file to determine the current state of the shell process. The problem is compunded with AppleScript's limited user interaction - about the most you can do is a 'display dialog', which doesn't give you much flexibility. In most cases, interactive apps are better handled via AppleScriptObjC which has the full (or, at least, fuller) UI options.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

find error do shell script with rsync command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.