On Wed, Jul 14, 2010 at 10:16, Sooraj S <[email protected]> wrote:
> Hi I am very new to perl. I want to login to a remote machine and
> check a directory exists or not.
>
> my code:
> ========
>
> using Net::Telnet;
>
> $t = new Net::Telnet();
> $t->open($remote_system);
> $t->login($username, $passwd);
>
> # this doesnot work.
> if (-d $my_dir) { print "ready to go"; }
>
> $t->close();
snip
Opening a telnet connection does not mean that Perl code will run on
the remote system. You should also not be using telnet as it is very
insecure. Look up ssh, configure your ssh keys, and try something
like this:
#!/usr/bin/perl
use strict;
use warnings;
my $host = shift;
my $dir = shift;
system "ssh", "-q", $host, "test", "-d", $dir;
my $rc = $? >> 8;
if ($rc == 0) {
print "$dir is a directory on $host\n";
} else {
print "$dir is not a directory on $host\n";
}
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/