2

I'm trying to use rsync over a custom shell created with fifo. However I cannot find a way to deal with it :

The script initsh to simulate a standard shell by fifo :

#!/bin/bash

rm fin
mkfifo fin
rm fout
mkfifo fout
rm ferr
mkfifo ferr
rm farg
mkfifo farg

read arg <farg
cat fin | /bin/bash -i -c "$arg" 1>fout 2>ferr

This script works well, you can test it by running (cat fout &) && echo ls > farg

The script rsh to pass to rsync :

#!/bin/bash

shift;
cat fout &
cat ferr 1>&2 &
echo "$@" | tee -a out > farg
cat | tee -a out > fin

sleep 2
kill %%
exit

The way to call rsync with :

rsync -e './rsh' user@fakehost:/

It works well when you run echo ./rsh, you got the shell like rsync wait for. But when rsync runs it, it does not close stdin, and so it waits for the stop (the EOF) of "cat | ...". I also tried with exec 0<>fin but it does not work at all.

Is there a trick to close the handle properly ? Or have you any other approach ?

akond
  • 1,622
  • 1
  • 10
  • 15
Xorax
  • 515
  • 1
  • 5
  • 9
  • Does the rsync session actually work, and you're having problems at the end of the session, or does rsync not work at all? And why pipe `cat fin` into bash instead of redirecting fin as standard input to bash? UUOC? – wurtel Oct 20 '15 at 12:58
  • Yes the rsync session work well and there is only problem at the end. I don't think there is any difference between cat fin | and < fin. – Xorax Oct 21 '15 at 12:21
  • 1
    Well, there's at least the extra overhead of a pipe and an extra process. – wurtel Oct 21 '15 at 13:43

1 Answers1

1

you could wait for the cat fout command to end as:

#!/bin/bash

shift;
cat fout &
foutid=$!
cat ferr 1>&2 &
echo "$@" | tee -a out > farg
cat | tee -a out > fin <&0 &

wait $foutid

sleep 2
kill %%
exit
adonis
  • 1,714
  • 9
  • 9
  • Thanks a lot ! it works ! However I don't understand why we need `cat | ` and `<&0` ? – Xorax Oct 21 '15 at 13:51
  • 1
    you don't need `cat |` it should work without it. `<&0` prevents tee from blocking when sent to bg - I'm not sure why it block in the first place. – adonis Oct 21 '15 at 13:54