By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,542 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,542 IT Pros & Developers. It's quick & easy.

Connecting to linux machine using Telnet Module.

P: 8
Hi,

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

Expand|Select|Wrap|Line Numbers
  1. use Net::Telnet;
  2. use Net::Ping;
  3. $telnet = new Net::Telnet (Timeout=>10,Errmode=>'die');
  4.  
  5. open (FILE,"C:/start.txt") or die ("Unable to open start.txt");
  6. while(<FILE>)
  7.     $cnt++ if !/^\s+?$/;
  8. close(FILE);
  9.  
  10. open fin,"C:/start.txt" or die $!;  
  11. my @data=<fin>;
  12. close(fin);
  13.  
  14. for(my $s=0;$s<$cnt;$s++)
  15. {
  16. $addr="$data[$s]"; 
  17. $addr =~s/^\s+//;
  18. $addr =~s/\s+$//;
  19. $p=Net::Ping->new("tcp");
  20.  
  21. if($p->ping($addr))
  22. {
  23. my $server ="$addr";
  24. $telnet->open($server);
  25. $telnet->waitfor('/login:/');
  26. $telnet->print('root');
  27. $telnet->waitfor('/password:/');
  28. $telnet->print('password');
  29. print $telnet->cmd("uname -a|tr -s ' '|cut -f1 -d ' '");
  30. }
  31. }

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

Expand|Select|Wrap|Line Numbers
  1. 192.168.**.1
  2. 192.168.**.20
  3. 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
May 26 '08 #1
Share this Question
Share on Google+
2 Replies


gpraghuram
Expert 100+
P: 1,275
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
May 27 '08 #2

P: 8
Thanks for your reply...
Now,my Script is woking fine........
May 29 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.