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,
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
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
Thanks in advance.
Regard's,
Thamayanthi
Comment