On Jul 15, 4:57 am, [email protected] ("Chas. Owens") wrote:
> 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.- Hide 
> quoted text -
>
> - Show quoted text -

Hi,
 Thanks for your reply. Actually i need to login to a remote machine
and do some series of steps including creating,editing and taring some
files and executing some other scripts..The remote machine is in our
local network itself..so there is no security issues and thats why i
am using telnet. Anyway thanks for ur explanation.

1. Using Net::Telnet module, can u suggest any way so that my above
given script will work.
2. If i use "ssh" as you suggest can i send password also through the
script..? if so how?
3. can u pls make me clear on this line - "my $rc = $? >> 8;"


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to