4

I am trying to have an infinite scp between two hosts but of course there is no such file large enough for this.

I tried

scp -l 512 192.168.1.1:/dev/zero /dev/null

But scp says /dev/zero not a regular file.

I need a consistent traffic between two hosts so I can try something on my router/firewall and I really need it to run for a long time.

Any suggestions? It does not have to be scp but I need to be able to specify the speed.

Thanks

2 Answers 2

8

The scp tool expects to copy a file. You can use ssh to transport an unending stream of bytes, and you can rate-limit with something like pv. The pertinent section of the man page for pv writes,

-L RATE, --rate-limit RATE Limit the transfer to a maximum of RATE bytes per second. A suffix of K, M, G, or T can be added to denote Kilobytes (*1024), Megabytes, and so on.

A suitable solution would be something like this, which rate-limits at approximately 10Mb/s (remember that 1MB/s is approximately 10Mb/s, after accounting for padding, network headers, etc.):

pv --rate-limit 1M </dev/zero | ssh [email protected] 'cat >/dev/null'

If you want bidirectional traffic flow, remove the quotes from the 'cat >/dev/null'.

8
  • +1. you can also do this with scp itself if you use a modernish shell (e.g. bash, ksh, zsh. not ash or dash) that supports process substitution. scp <(pv ...) [email protected]:/dev/null
    – cas
    Commented Jan 24, 2018 at 2:13
  • I tried this on CentOS 7 scp still compliants about not a regular file. Commented Jan 24, 2018 at 3:11
  • so it does...I should have tested that before commenting. maybe there is some valid reason for scp to care whether a file is a regular file or not. or maybe it's just some over-zealous special-case handling. dunno.
    – cas
    Commented Jan 24, 2018 at 6:17
  • @cas it introduces ambiguity, so it's blocked. Consider scp /dev/sdc3 remote:/dev/sdc3 where the destination does not exist. Should this copy the device node? What about its contents? Since sdc3 is missing on the target should we copy the contents to a file on the destination? Commented Jan 24, 2018 at 8:04
  • 1
    rsync is different to ssh or scp. BTW, for live-migrating VMs, I zfs send the VM's ZVOL to my secondary VM host :), and that's usually very quick because it's only a small update since the most recent snapshot send. The DRBD idea in the strugglers.net article is nicely implemented in google's ganeti. I've got ganeti working with ZFS at home, but I don't really need ganeti here. libvirt plus my own scripts suffice. $workplaces that have paid me to do VM stuff tend to go for vmware, xen, openstack, or containers with docker. I quite like the latter 3.
    – cas
    Commented Jan 24, 2018 at 10:14
0

from commandlinefu.com:
dd if=/dev/zero bs=4096 count=1048576 | ssh [email protected] 'cat > /dev/null'

As a helpful user posted, this will stop at 4GiB, which is not infinite. Therefore:

</dev/zero ssh [email protected] 'cat > /dev/null'

1

You must log in to answer this question.

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