Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

At the end of a successful rsync job, I get the typical:

sent 6022622 bytes  received 4751961 bytes  69738.40 bytes/sec
total size is 3328464484  speedup is 308.92

I call my rsync job via a shell script and at the end of the script I write to a text file as a log. Without logging the entire rsync job to a text file, is there a way just to capture whether or not this message is output at the end so I could write something like 'OK' as part of my output to signify the sync ran successfully?

Thank you!

share|improve this question
4  
Why not just use the exit code of the process? After rsync has finished, have your script check that $? is equal to 0. That would signify there were no errors. –  yoonix Apr 8 '13 at 22:37
    
That'd work actually - thank you! –  Jason Apr 8 '13 at 23:00

1 Answer 1

As already indicated in the comments, the best way is to check the return code of rsync. Here's some bash code you may want to use to convert the return codes to meaningful strings:

rsync -a -v -h -i --stats --dry-run -A -H $source $target

case $? in
  0)
    echo "\e[32mSuccess"
    ;;
  1)
    echo "Syntax or usage error"
    ;;
  2)
    echo "Protocol incompatibility"
    ;;
  3)
    echo "Errors selecting input/output files, dirs"
    ;;
  4)
    echo "Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server."
    ;;
  5)
    echo "Error starting client-server protocol"
    ;;
  6)
    echo "Daemon unable to append to log-file"
    ;;
  10)
    echo "Error in socket I/O"
    ;;
  11)
    echo "Error in file I/O"
    ;;
  12)
    echo "Error in rsync protocol data stream"
    ;;
  13)
    echo "Errors with program diagnostics"
    ;;
  14)
    echo "Error in IPC code"
    ;;
  20)
    echo "Received SIGUSR1 or SIGINT"
    ;;
  21)
    echo "Some error returned by waitpid()"
    ;;
  22)
    echo "Error allocating core memory buffers"
    ;;
  23)
    echo "Partial transfer due to error"
    ;;
  24)
    echo "Partial transfer due to vanished source files"
    ;;
  25)
    echo "The --max-delete limit stopped deletions"
    ;;
  30)
    echo "Timeout in data send/receive"
    ;;
  35)
    echo "Timeout waiting for daemon connection"
    ;;
  *)
    echo "Unknown return code $? from rsync"
esac
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.