2

I have 2 systems

1: 192.168.0.31 
2: 192.168.0.32

From system 1 terminal I executed below command

tar -zcf - test | pv | nc -l -p 5555 -q 5

From system 2 terminal I executed below command

nc 192.168.0.31 5555 | pv | tar -zxf -

Now full test folder with all containing files copied to system 2

How can I to schedule both commands using crontab or something else?

Yaron
  • 12,828
  • 7
  • 42
  • 55
shaji
  • 51
  • 2
  • 9
  • You should really do that using SCP, doing this with NC is very unsecure as there is no authentication or encryption whatsoever involved. – Gewure Aug 24 '17 at 13:50

1 Answers1

2

It seems that you would like to make a backup/copy of data in one computer into another.

A very simple and secure solution might be using scp which is based on ssh.

scp sample command might look like:

scp -r /path/to/local/folder user@remotehost:/path/to/remote/folder

e.g.

  • Assuming that:

    • your username is shaji
    • You wan to copy files from 192.168.0.31 /home/shaji
    • To 192.168.0.32 into folder /backup/shaji/backup
  • You should run the following command on 192.168.0.31:

    scp -r /home/shaji shaji@192.168.0.32:/home/shaji/backup

Note: You can run the scp command using crontab

man scp

scp — secure copy (remote file copy program)

DESCRIPTION

 scp copies files between hosts on a network.  It uses ssh(1) for data
 transfer, and uses the same authentication and provides the same security
 as ssh(1).  Unlike rcp(1), scp will ask for passwords or passphrases if
 they are needed for authentication.

 File names may contain a user and host specification to indicate that the
 file is to be copied to/from that host.  Local file names can be made
 explicit using absolute or relative pathnames to avoid scp treating file
 names containing ‘:’ as host specifiers.  Copies between two remote hosts
 are also permitted.

 -r      Recursively copy entire directories.  Note that scp follows
         symbolic links encountered in the tree traversal.

There are some pre-requites:

  • sshd should run on the remote host
  • Setting password-less ssh access to remote host - see askubuntu Q&A
Yaron
  • 12,828
  • 7
  • 42
  • 55
  • I tried to run command but permission denied. – shaji Aug 24 '17 at 12:59
  • I appreciate your help please confirm that command should be run on system1 or system2 – shaji Aug 24 '17 at 13:15
  • Now I tested the command on system 1 and its working fine, files from system1 are copying to system2. Is there any simple way to make it password less? – shaji Aug 24 '17 at 13:20
  • @shaji - as mentioned in the link of [this Q&A](https://askubuntu.com/q/46930/544264) - you should execute `ssh-keygen` followed by `ssh-copy-id user@host` - please review this Q&A – Yaron Aug 24 '17 at 13:23
  • @shaji - did my answer solve your problem? – Yaron Aug 24 '17 at 13:55
  • 1
    Yes I managed it as you suggested thank you so much @Yaron – shaji Sep 03 '17 at 13:17
  • @shaji - if my answer solve your problem please accept it – Yaron Dec 13 '17 at 13:31