How to give username and password to a machine in perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • susinthaa
    New Member
    • Jun 2007
    • 30

    How to give username and password to a machine in perl

    Hi,

    How to use a solaris mount command in perl?
    I tried that telnet to the solaris machine.
    For that solaris machine, how can I give the username and password?

    [CODE=perl]
    use Net::Telnet;

    use strict;

    my $cmd = shift;
    my $ip1 = shift;
    my $ip2 = shift;
    my $vol = shift;
    my $mntpnt = shift;

    print "command name is $cmd\n";
    print "$ip1\n";
    print "$ip2\n";
    print "$vol\n";
    print "$mntpnt\n" ;

    my $t = new Net::Telnet(
    Timeout => 300,
    rrmode => 'die',
    );
    $t->open("$ip2") ;

    my @file=$t->cmd("mount") ;
    print "@file";
    [/CODE]

    Where I am wrong?
    please guide me.

    Thanks and Regards,
    susi.
    Last edited by miller; Jul 11 '07, 09:20 AM. Reason: Code Tag and ReFormatting
  • susinthaa
    New Member
    • Jun 2007
    • 30

    #2
    Hi, This code is working fine to telnet to a solaris machine with username and password.

    [CODE=perl]
    use Net::Telnet;

    use strict;

    my $UNIXIP = "<IP REMOVED BY MOD>";
    my $user = "<USER REMOVED BY MOD>";
    my $pass = "<PASS REMOVED BY MOD>";

    print "MY - $UNIXIP,$user,$ pass \n";

    my $u = new Net::Telnet(
    Host => $UNIXIP,
    Timeout => 60,
    );
    $u->login($user, $pass) or die "Failed to login Unix connection $!\n";

    my @res = $u->cmd("ls");

    print "@res";
    [/CODE]
    Last edited by miller; Jul 11 '07, 09:18 AM. Reason: Code Tag and ReFormatting

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Yes, that newer version looks almost straight out of the documentation

      cpan Net::Telnet

      well done,
      - Miller

      Comment

      Working...