Click here to get back home

ssh into remote nodes, do mulitple commands

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
ssh into remote nodes, do mulitple commands Nene 01-29-2008
Get Chitika Premium
Posted by Nene on January 29, 2008, 8:32 pm
Please log in for more thread options
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: $!";

}

}
}


Posted by zentara on January 30, 2008, 9:07 am
Please log in for more thread options
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/listinfo/ssh-sftp-perl-users

zentara

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

Posted by J. Gleixner on January 31, 2008, 11:12 am
Please log in for more thread options
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.

Similar ThreadsPosted
remote commands on unix from win :( October 16, 2006, 11:26 pm
exit status of remote commands October 4, 2007, 6:45 am
XML::LibXML, newlines in nodes, and entities... July 6, 2005, 4:56 pm
Identify nodes in the same level using a pattern March 15, 2006, 1:14 pm
Remote.pm (File::Remote) problem February 28, 2006, 9:50 pm
about ssh remote July 4, 2006, 12:30 pm
File::Remote December 23, 2004, 11:45 pm
Remote Permissions Problem October 21, 2004, 12:15 pm
Using DBI for Remote myql connection November 13, 2004, 6:12 am
Remote command execution April 12, 2005, 8:02 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap