这个语法有什么问题?由于硬盘空间不足,如何直接在远程 ftp 上写入输出?
此命令有效,但没有硬盘空间来获取完整结果:
find /somedir/ -name '*.*' -exec grep -i 'some string' /dev/null {} + >> /somedir/output.txt
我尝试了类似的方法,但收到错误“操作不适用”:
find /somedir/ -name '*.*' -exec grep -i 'some string' /dev/null {} + >> ftp -u ftp://[email protected] /somedir/output.txt
答案1
grep -r 'some sting' /somedir | ssh user@host "dd of=outputfile"
如果您可以使用 ssh 而不是 ftp,那么这可能会起作用。
答案2
我这样做了,我不知道这是否是更清晰的方法。
#! /usr/bin/perl -w
use Net::FTP;
open(TMPOUT, ">>","/tmp/tmpout.txt");
*STDOUT = *TMPOUT; ### Redirect STDOUT to /tmp/tmpout.txt
#select TMPOUT;
my ($ftp, $host, $user, $pass, $dir, $fpath);
$host = "localhost";
$user = "myftpuser";
$pass = "myftppassword";
$dir = "/tmp";
$ftp = Net::FTP->new($host, Debug => 0);
$ftp->login($user, $pass) || die $ftp->message;
$ftp->cwd($dir);
while(<STDIN>) { print $_ . "\n"; } ####Printing the STDING to /tmp/tmpout.txt
$ftp->append("/tmp/tmpout.txt", "myremoteout.txt"); ### Now i append the oupout of the local file /tmp/tmpout.txt to the remote ftp file /tmp/myremoteout.txt
$ftp->quit;
现在chmod +x f.pl
和find / -type f | ./f.pl
grep "^/" /tmp/myremoteout.txt
ftp 服务器上的输出 :
/usr/share/doc/gcc-4.7-base/README.Bugs
/usr/share/doc/gcc-4.7-base/NEWS.html
/usr/share/doc/gcc-4.7-base/changelog.Debian.gz
/usr/share/doc/gcc-4.7-base/changelog.gz
/usr/share/doc/gcc-4.7-base/quadmath/changelog.gz
/usr/share/doc/gcc-4.7-base/test-summary.gz
/usr/share/doc/gcc-4.7-base/gomp/changelog.gz
/usr/share/doc/gcc-4.7-base/TODO.Debian
/usr/share/doc/gcc-4.7-base/gcc/changelog.gz
/usr/share/doc/gcc-4.7-base/README.ssp
/usr/share/doc/gcc-4.7-base/README.Debian.amd64.gz
/usr/share/doc/gcc-4.7-base/test-summaries/obj-c++.sum.gz
/usr/share/doc/gcc-4.7-base/test-summaries/libmudflap.sum.gz
/usr/share/doc/gcc-4.7-base/test-summaries/libgomp.sum.gz
/usr/share/doc/gcc-4.7-base/test-summaries/libstdc++.sum.gz
/usr/share/doc/gcc-4.7-base/test-summaries/libgo.sum.gz
/usr/share/doc/gcc-4.7-base/test-summaries/go.sum.gz