0

I'm using Mac 10.9.5 and bash shell. In our environment, we have to go through a proxy (a CentOS machine) to SSH properly into a destination machine (another CentOS machine). What I would like to do is create a shortcut so that I can scp files quickly to the destination server, something like

scp localfile.txt davea@server:/home/davea

But right now, I have to do multiple commands to transfer the file …

scp localfile.txt davea@proxy:/home/davea
ssh davea@proxy
scp localfile.txt davea@server:/home/davea

Is it possible to condense the above into one line?

Dave
  • 1
  • 1

2 Answers2

1

How about a function in you .bash_profile

scps () {
    if [ -f $1 ] ; then
        scp $1 davea@proxy:/home/davea && ssh davea@proxy && scp $1 davea@server:/home/davea
    else
        echo "'$1' is not a valid file!"
    fi
}

Then you can use scps filename to copy filename to davea@server:/home/davea.

jherran
  • 1,879
  • 3
  • 20
  • 28
  • 1
    Hi, I gave this a go but the result is that I end up SSH'ed into the proxy server and the file hasn't been transferred to the destination. – Dave Nov 21 '14 at 18:04
  • I bet, when he said `ssh davea@proxy` (and then) `scp localfile.txt davea@server:/home/davea`, Dave meant `ssh davea@proxy` and then `scp localfile.txt davea@server:/home/davea` _from the shell prompt on the `proxy` host_. Your `ssh davea@proxy && scp $1 davea@server:/home/davea` isn't going to do that. Something like `echo "scp $1 davea@server:/home/davea" | ssh davea@proxy` _might_ work, but I doubt that it's optimal. – G-Man Says 'Reinstate Monica' Nov 21 '14 at 18:41
  • Hi G-Man, What you say is definitely what I intended. However, in your suggested solution, where is the "scp $1 davea@proxy:/home/davea" portion of the command? – Dave Nov 21 '14 at 20:11
0

Consider using rsync to automatically copy files from the proxy to the destination:

rsync local-file user@remote-host:remote-file
Andreas F
  • 333
  • 1
  • 12
  • Thanks but I wanted to do everything in one line. As I udnersatnd it, your command only works once I am on the proxy server. – Dave Nov 24 '14 at 17:39
  • I would set the rsync to copy automatically, e.g. by adding to _/etc/crontab_ * * * * * bash – Andreas F Nov 24 '14 at 17:48