13

I'd made a script for launching parallel rsync process:

#! /bin/bash
LIST=$1
DEST_DIR=$2
RSYNC_OPTS=$3
#echo "rsyncing From=$SRC_DIR To=$DEST_DIR RSYNC_OPTS=$RSYNC_OPTS"
echo $LIST|xargs -n1 -d, echo|xargs -n1 -P 0 -I% rsync --rsync-path='sudo rsync' ${RSYNC_OPTS} % ${DEST_DIR}

Then, I have problems to get the exit status of the rsync process. I know that is possible to get an array of pipestatus, but I need to catch the exit code to know if the rsync was made successfully or not.

Anyone knows?

bLuEdDy
  • 193
  • 1
  • 7
  • You already mentioned `$PIPESTATUS`: `${PIPESTATUS[2]}` will contain the exit status of the second `xargs` command. This will be 123 if `rsync` exited with a status of 1-125 (see the exit status section here: http://unixhelp.ed.ac.uk/CGI/man-cgi?xargs) – Josh Jolly Apr 14 '14 at 09:06
  • Hi Josh, thanks for your reply. Nevertheless, I need the exit code of the rysnc, not the xargs exit code. Something like this : http://wpkg.org/Rsync_exit_codes – bLuEdDy Apr 14 '14 at 09:13
  • 1
    Not sure you would be able to get the rsync's specific exit status using xargs like this, it will be masked by xargs. Maybe you could loop through `$LIST` instead? – Josh Jolly Apr 14 '14 at 10:05
  • 2
    duplicate question: http://unix.stackexchange.com/q/124649/4667 – glenn jackman Apr 14 '14 at 12:23

1 Answers1

10

The man page for xargs shows the possible exit status values, however it can only produce a single aggregated exit code, not an exit code per child that it runs. You could try one of these options:

  • Have the process that xargs spawns print its exit code and have the parent task parse all the exit code outputs to determine the exit code for each rsync.
  • Use GNU parallel with the --joblog option. This will create a file containing all the commands which were run in parallel along with its exit code and other information. This file could then be parsed after parallel exits to determine which rsync commands failed and their respective error codes.
Austin Phillips
  • 15,228
  • 2
  • 51
  • 50