in reply to scp output without having to use "Net::SCP" in Perl

What exactly is in $output? It could be being mistaken for an argument to scp.

Try hard setting all the system() arguments manually to their actual values, and go from there. For instance, this works for me:

perl -e '$o="this.fil"; system("/usr/bin/scp", $o, "steve\@hostname:/h +ome/steve/");'

-stevieb

Replies are listed 'Best First'.
Re^2: scp output without having to use "Net::SCP" in Perl
by pjzero@90 (Novice) on Jun 02, 2015 at 22:20 UTC
    stevieb, $output is the output of a command, for example, let's say $output = `ls -ltra /tmp`; Thanks, -- pjzero@90
      Then try something like this:
      system("ls -lrta /tmp | ssh $user\@$host 'cat >/tmp/LOGS/'");

      You can not use scp to copy data from an scalar in the process memory. It only works for files stored in the file system.

      You're trying to scp a command, and the output, to another host? Try breaking that up into separate tasks -- this is what /tmp is for. Connect via ssh to the host and run your command, redirecting the output to /tmp/someuniquefile, then scp the file to whatever location you want. When you start introducing commands with pipes and such in variables for remote execution, the complexity increases. Do one task at a time, and you can manually verify that they work separately.

      Edit: I misread a piece -- you don't scp data, you scp a file. Save the output to /tmp/something, and scp that.
        Let's try this again, I do a ssh over to a host, and grab certain files from /tmp, this works fine, I then want to send these logs to a second host. my @OUTPUT = `ssh $USER\@$host ls -ltr /tmp | grep logs`; foreach my $output (@OUTPUT) { chomp ($output); system("/usr/bin/scp", "--", $output, "user\@host:/home/user/logs"; } I now get "No such file or directory", so your right, I need to put the log itself into a file, any ideas or should I use a different approach? Thanks, -- pjzero@90