1

I can do every single step:
1, compress file using tar
2, copy to remote machine using scp
3, login remote machine using ssh, need password
4, uncompress the file
but, I want to write a single script to do the work, anyone suggestion?

2
  • 1
    tar does not compress. It just puts multiple files together into one single file, but without any compression. You use e.g. gzip or bzip to compress a tar file. The tar command is still necessary though, because those compression algorithms can only operate on single files.
    – Byte Commander
    Jan 31, 2016 at 13:43
  • I use the -z flag to compress
    – Liu Hao
    Feb 1, 2016 at 8:49

1 Answer 1

4

Why don't you use rsync to do that? From the computer were you want to get the file

rsync [email protected]:/home/myuser/mydir/myfile myfile

will move the file over the two computers, taking care of the transportation. You can even pass recursively (-r) if you want to sync the whole directory.

Regarding compressing the data, you can obtain it via -z option, but keep in mind that if your connection is fast and your CPU is slow (mobile devices) you will have better performances just transferring the data without compressing them.

--

Following the comment below, I suggested to look into fabric (http://www.fabfile.org/), which will give you the ability to operate on a server by remote.

so for example as a template you could:

```

from fabric.api import run

def kill_and_replace():
    run('killall myserverprocess')
    run('cp mynewfile myoldfile')

```

1
  • I'm sorry, I didn't said clearly, Acutally, it's not just sync files, I need login to remote machine to kill the server program, and then replace the files it needed, and then restart it, so it will be updated
    – Liu Hao
    Feb 1, 2016 at 8:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .