For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > January 2008 > ssh into remote nodes, do mulitple commands









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ssh into remote nodes, do mulitple commands
Nene

2008-01-29, 10:18 pm

Hello,

I'm trying to use Net::SSH to ssh into 3 nodes and move/copy files
with File::Copy. For now, I scripted it to find files of a certain
age and move them.
The $cmd variable is working, but when I try to move the files, it
errors with copy failed. Please critique or suggest a better way.
Thanks in advance!!!!
########################################
##############

#!/usr/bin/perl -w
use Net::SSH::Perl qw(sshopen2);
use strict;


my %LIST = (

1 => "node1",
2 => "node1",
3 => "node1"

);

foreach my $ESP (sort values %LIST) {


my $user = "user1";
my $host = $ESP;
my $cmd = "sudo find /somedir -name file.err -mtime 1 -exec ls -lt {}
';'";



sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
print "Connected to $host\n";

while (<READER> ) {

if ( $_ ) {
use File::Copy;

move("/tmp/rod","/tmp/nasty") or die "Copy failed: $!";

}

}
}

zentara

2008-01-30, 7:18 pm

On Tue, 29 Jan 2008 17:32:41 -0800 (PST), Nene <rodbass63@gmail.com>
wrote:

>Hello,
>
>I'm trying to use Net::SSH to ssh into 3 nodes and move/copy files
>with File::Copy. For now, I scripted it to find files of a certain
>age and move them.
>The $cmd variable is working, but when I try to move the files, it
>errors with copy failed. Please critique or suggest a better way.
>Thanks in advance!!!!


Try Net::SSH2 , its better. Sftp is incorporated
into it, and you probably want to use it for file transfers.

See:
http://perlmonks.org?node_id=569657

also ask on the SSH maillist
http://lists.sourceforge.net/lists/...sftp-perl-users

zentara

--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
J. Gleixner

2008-01-31, 7:21 pm

Nene wrote:
> Hello,
>
> I'm trying to use Net::SSH to ssh into 3 nodes and move/copy files
> with File::Copy. For now, I scripted it to find files of a certain
> age and move them.
> The $cmd variable is working, but when I try to move the files, it
> errors with copy failed. Please critique or suggest a better way.

[...]
> sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
> print "Connected to $host\n";
>
> while (<READER> ) {
>
> if ( $_ ) {
> use File::Copy;
>
> move("/tmp/rod","/tmp/nasty") or die "Copy failed: $!";
>
> }


You're 'use'ing File::Copy on the machine that's running the script, not
on the remote host. So your 'move' is trying to move those files on the
host machine, not $host.

Probably easiest to just do "mv /tmp/rod /tmp/nasty" in another sshopen2
or better would be to modify the find command to move the files as
part of the exec, instead of ls -lt -- which is sort of useless.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com