2

What is wrong with this syntax? How to write output directly on remote ftp because lack of space on HDD?

This command is working but there is no HDD space to get the full result:

find /somedir/ -name '*.*' -exec grep -i 'some string' /dev/null {} + >> /somedir/output.txt

I tryed something like but I get Error "Operation not applicable":

find /somedir/ -name '*.*' -exec grep -i 'some string' /dev/null {} + >> ftp -u ftp://user@ftp.domain.com /somedir/output.txt
masegaloeh
  • 18,236
  • 10
  • 57
  • 106
eraser
  • 21
  • 2
  • 1
    AFAIK the classical ftp command isn't easily scriptable and you should probably use some more recent and advanced such `curl` instead which does takes FTP commands on stdin. Alternatively if you only need a relatively small amount of disk space, sacrifice some memory and create an in-memory filesystem `mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk`. – HBruijn Jan 12 '15 at 12:52
  • On (gnu-) grep you can use "grep -r 'some sting' /somedir" ... as a slightly easier syntax. Also, as stated, you can't output-redirect to ftp, but you can do it with ssh. – Sig-IO Jan 13 '15 at 11:07

2 Answers2

1
grep -r 'some sting' /somedir | ssh user@host "dd of=outputfile"

That might do the trick, if you can use ssh in stead of ftp.

peterh
  • 4,953
  • 13
  • 30
  • 44
Sig-IO
  • 1,056
  • 9
  • 11
1

I did this, i don't know if this is the more clearly way to that.

#! /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;

Now chmod +x f.pl and find / -type f | ./f.pl

output of grep "^/" /tmp/myremoteout.txt on the ftp server:

/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
c4f4t0r
  • 5,301
  • 3
  • 31
  • 42