ACPI administration advocacy advocacy advocacy opinion alsa amarok apache apple apt aptitude audio audo authentication automount avi awk bash BIOS boot business cache calendar calibre cdr cdrecord censorship commandline computerscience console convert cron cut database date debian degree design desktop development disk dpkg dvd economics education emacs email europe exim faad ffmpeg file files firefox firewall flash foss freedom ftp fun fuse git gnumeric graphics grep growisofs grub gtkpod hardware hardware html idiocy image imagemagick images installation ip iphone ipod iptables iso itunes ivman kde kernel keyboard knoppix lame laptop latex linux locale lockin longlines m4a microsoft mimetypes minitab mount mp3 mp4 mplayer multimedia music mysql network nfs nfs4 nmap openbox openoffice opinion opinion partition pdf perl php politics postgresql printing privacy programming rant remote rhythmbox rss rsync rxvt scp screengrab screenshot script scripting scsi security sed server shell siteadmin sitenews sitesoftware skype skype slackware sound sox spam spreadsheet ssh statistics subversion sudo svk swap t23 t43 terminal text thinkpad thunderbird time timezone ubuntu udev upgrade usb usbmount users uuid versioncontrol vfat video vnc windows wine wordpress wordprocessing X40 xwindows xwindows youtube
The premier tool for copying a file or two from one machine to another is scp. It's simple. It's effective. That's why there's a FAQ, which is will scp accept data from STDIN?
The answer is 'no'.
Some people complain about this, but it's not a bug, it's a feature.
If you want to take a stream of data on a computer and dump it in a file, you don't use the cp command, do you? Rather, you do something like this:
echo "some text" > afile.txt
What's true of an operation on one machine is true of an operation across machines. So, if you have a stream of data produced by a script on one machine and you want it in a file on another machine, that's not copying the data, it's storing some data produced on one machine in a file on another machine.
When the problem is reframed like that, a number of solutions become apparent. Probably the easiest is this:
echo "some text" | ssh user@remote.host "cat > /remote/file"
Obviously, echo "some text" should be changed to any command or script that produces a stream of data to STDOUT and the host and file names should be changed as appropriate.
Actually, scp *does* support reading from stdin; it just seems to be undocumented. The scp process on the local machine establishes an ssh connection to the remote machine and then invokes an scp process on the remote machine, and that remote scp process has to read from stdin.
The command > scp foo remote:/path/to/bar
invokes the following on the machine "remote": > ssh -t /path/to/bar
I discovered this while debugging a "validate-rsync" script to use in the "command=" rule for an ssh key.
Posted by John Abreau on 2011-12-22 21:09:20.