5

I am working on a script which will be used to transfer a file (using rsync) from a remote location and then perform some basic operations on the retrieved content.

When I initially connect to the remote location (not running an rsync daemon, I'm just using rsync to retrieve the files) I am placed in a non-standard shell. In order to enter the bash shell I need to enter "run util bash". Is there a way to execute "run util bash" before rsync begins to transfer the files over?

I am open to other suggestions if there is a way to do this using scp/ftp instead of rsync.

lacrosse1991
  • 2,972
  • 7
  • 38
  • 47
  • What kind of shell is this and what does it support? Can you run `ssh thathost run util bash` to get a bash session? – that other guy May 25 '14 at 04:32
  • Hello, running "ssh hostiP 'run util bash'" just causes it to hang, think I had run into a previous issue where it would not allow me to send commands like that, so I'm not sure if it would even be possible to do what I had described in the original request. The shell itself is a traffic management shell in an F5 viprion load balancer, it has functions specific to the traffic manager running on the machine, does not really have any commands in terms of ftp, ssh, etc until you enter the bash shell – lacrosse1991 May 25 '14 at 23:02
  • Google suggests that you have to use `run /util bash` instead. Does that work better? – that other guy May 26 '14 at 02:36

2 Answers2

7

One way is to exectue rsync from the server, instead of from the client. An ssh reverse tunnel allows us to temporarily access the local machine from the remote server.

  1. Assume the local machine has an ssh server on port 22
  2. Shh into the remote host while specifying a reverse tunnel that maps a port in the remote machine (in this example let us use 2222) to port 22 in our local machine
  3. Execute your rsync command, replacing any reference to your local machine with the reverse ssh tunnel address: my-local-user@localhost
  4. Add a port option to rsync's ssh to have it use the 2222 port.

The command:

ssh -R 2222:localhost:22 remoteuser@remotemachine << EOF

  # we are on the remote server.
  # we can ssh back into the box running the ssh client via ${REMOTE_PORT}
  run utils bash
  rsync -e "ssh -p 2222" --args /path/to/remote/source remoteuser@localhost:/path/to/local/machine/dest
EOF

Reference to pass complicated commands to ssh: What is the cleanest way to ssh and run multiple commands in Bash?

ealfonso
  • 6,622
  • 5
  • 39
  • 67
  • sorry for commenting on a 4 year old answer, but if you bind to port `10000` in `10000:127.0.0.1:22` why are you invoking `ssh -p 1000` to port `1000` instead? – Srini May 04 '18 at 20:17
  • you're right, it should be 1000, not 10000. I edited the answer to use port variables instead – ealfonso May 04 '18 at 21:58
2

You can achieve it using --rsync-path also. E.g rsync --rsync-path="run util bash && rsync" -e "ssh -T -c aes128-ctr -o Compression=no -x" ./tmp root@example.com:~

--rsync-path is normally used to specify what program is to be run on the remote machine to start-up rsync. Often used when rsync is not in the default remote-shell’s path (e.g. –rsync-path=/usr/local/bin/rsync). Note that PROGRAM is run with the help of a shell, so it can be any program, script, or command sequence you’d care to run, so long as it does not corrupt the standard-in & standard-out that rsync is using to communicate.

For more details refer

SkyRar
  • 1,107
  • 1
  • 20
  • 37