in reply to Detecting failed piped command run via ssh

I know it's not a direct solution to your problem, but I recently encountered a different approach to a similar problem whereby the...
  1. pipeline was split into its individual commands
  2. each of the commands is echoed to a temporary sh(1) script on the host
  3. the temporary script is then run on the host using ssh(1) & sh(1)

e.g. (escaping as required)

# ssh $HOST "cat > /tmp/script" << ! rm -f /tmp/files /tmp/contents sudo find $TARGET_DIR -name \'$TARGET_FILE\' > /tmp/files || exit $? sudo cat /tmp/files | cpio -oBO /tmp/contents --format ustar" || exit +$? bzip2 -9 -c /tmp/contents || exit $? exit 0 ! # ssh $HOST "sudo sh /tmp/script"
... or similar :-D

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Detecting failed piped command run via ssh
by devnull (Initiate) on Apr 08, 2009 at 11:02 UTC
    Thanks, I am sure that this approach would work, but I am a little reluctant due to the race conditions, security considerations and extra code. The "ssh/find/cpio/bzip2" approach is simple, and the only drawback is not telling the user that they've failed to get the right dir/file is probably acceptable - it just doesn't give that satisfaction of doing a good job.