I am frequently updating files from a development enviroment to a production one in different servers so the paths are the same in both hosts and it becomes kind of a repetitive procedure to update a file and indicate the same path for the scp parameters.

Is there a way to use brace expansion or other technique with scp parameters? I know one of them, origin or destination must include the user@host: at the start.

What I am trying to do is something like:

scp user@{dev-server,production-server}:/path/to/file
  • 5
    Why not do just that, with the braces? – Gilles 'SO- stop being evil' Aug 3 '12 at 23:43
  • scp isn't working with brace expansion (braces). Any example? – altmas5 Aug 5 '12 at 19:54
  • 1
    Brace expansion is performed by the shell, not by scp. The command you wrote is expanded by the shell into scp user@dev-server:/path/to/file user@production-server:/path/to/file. – Gilles 'SO- stop being evil' Aug 5 '12 at 20:16

I propose two solutions not all using scp:

1. Use .ssh/config to help

Ie: put something like this in your .ssh/config

Host p
HostName production.domain.com
Host d
HostName development.domain.com

Then you can shorten your scp command:

scp user@d:/path user@p:/path

2. Use source control software like git. So when you're done with debugging and coding and stuff, you do this (simplified):

git add /path/to/my_file
git commit -m "new version and features done"
git push production master

(Just setup your git to use ssh)

3. Use qscp, or quick-scp - a bash script designed especially for your convenience :) https://github.com/zladuric/quick-scp Basically, get the qscp file and make it executable. (and change the defaults to your environment).

It will take one mandatory and two optional parameters. Example:

./qscp file     # it will use defaults
./qscp path/to/dir  dest.server.com # uses default source, but to other dest
./qscp /abs/path/to/file dest.srv.com src.srv.com # takes both dest and source server args

The scrpt should be easy to customize to your specific needs, but it is not extremely robust yet. You may have to adjust location of the scp binary, your ssh_key files or something similar.

How about them apples? :)

|improve this answer|||||
  • I want to avoid typing the path 2 times not the hostnames.I know using a SCM is the right solution for updating my production server but is not an option right now. – altmas5 Aug 5 '12 at 20:19
  • 1
    ok, then qscp is created as your answer :) but of course, it will mostly use as a guideline so you can work with that :) – Zlatko Aug 6 '12 at 11:28
  • awesome, I will take a look of it. Thank you – altmas5 Aug 6 '12 at 17:14

I think it is better to alias the command which you are executing everytime to even reduce typing.

Add the command in the .bashrc file of the user:

alias tx='scp user@{dev-server,production-server}:/path/to/file'

This will help to reduce the typing errors which may happen while typing the whole command.

But I think the way you are this doing is not correct at all. As zladuric told in the second way, you should use some version control system to maintain you code database. This will allow you to revert back to any previous version.

|improve this answer|||||
  • scp is not accepting brace expasion, so the alias is not going to work either. – altmas5 Aug 5 '12 at 19:53
  • 1
    this is because ur scp syntax is wrong..it shud be something like: scp /path/to/file user@roduction-server:/path/to/file – pradeepchhetri Aug 5 '12 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.