Connecting to linux machine using Telnet Module.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thamayanthi
    New Member
    • Feb 2008
    • 8

    Connecting to linux machine using Telnet Module.

    Hi,

    The below code is used to connect to the remote machine using Telnet module in perl.

    [CODE=perl]use Net::Telnet;
    use Net::Ping;
    $telnet = new Net::Telnet (Timeout=>10,Er rmode=>'die');

    open (FILE,"C:/start.txt") or die ("Unable to open start.txt");
    while(<FILE>)
    {
    $cnt++ if !/^\s+?$/;
    }
    close(FILE);

    open fin,"C:/start.txt" or die $!;
    my @data=<fin>;
    close(fin);

    for(my $s=0;$s<$cnt;$s ++)
    {
    $addr="$data[$s]";
    $addr =~s/^\s+//;
    $addr =~s/\s+$//;
    $p=Net::Ping->new("tcp");

    if($p->ping($addr))
    {
    my $server ="$addr";
    $telnet->open($server );
    $telnet->waitfor('/login:/');
    $telnet->print('root' );
    $telnet->waitfor('/password:/');
    $telnet->print('passwor d');
    print $telnet->cmd("uname -a|tr -s ' '|cut -f1 -d ' '");
    }
    }[/CODE]


    The Start.txt file contains the list of IP Address as shown below,

    Code:
    192.168.**.1
    192.168.**.20
    192.168.**.25
    The script will read the IP Address from the file start.txt one by one,by executing the given UserID and Password to produce the output.Suppose the UserID and Password for any of these Machine is wrong then it is exiting out of the Script without reading the Next IP Address.I want the Solution like,if the password is wrong for any of the machine then my script should read the next IP Address from the file instead of exiting out of the script.Please any one help me in this........... ..

    Thanks in advance.


    Regard's,
    Thamayanthi
    Last edited by eWish; May 26 '08, 04:32 AM. Reason: Please use code tags
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    The default errormode is die in net::telnet.
    You can make use of errmode() function in that module to get around that.
    Read the documentation for more info about errmode.

    Raghuram

    Comment

    • thamayanthi
      New Member
      • Feb 2008
      • 8

      #3
      Thanks for your reply...
      Now,my Script is woking fine........

      Comment

      Working...