HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- perl telnet on multiple host
Operating System - Linux
        1839839
        Members
    
    
        2215
        Online
    
    
        110156
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
	
		
			
            
                
            Go to solution
        
            
		
		
			
            	
	
		
        
		
	
	
		Topic Options
			
				
					
	
			
		
	- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2004 11:09 PM
09-14-2004 11:09 PM
			
				
					
					
						hi all,
I try telnet on multiple host with perl. Hosts are stored in hosts.txt but I don't now how to use them. (I can only use ARGV[0] from line)
telnet.pl 10.3.0.29
----
#!/usr/bin/perl
use strict;
use Net::Telnet ();
my $host = $ARGV[0];
my $username = "user";
my $password = "passwd";
my $conn = new Net::Telnet (Timeout => 1,
Errmode => 'return',
);
  
$conn->open($host);
$conn->login($username,$password);
print $conn->cmd('uname -a');
$conn->close();
-----
I tried
for ($i = 0; `cat hosts.txt`; ++$i) but it doesn't work.
How can I retrive hosts form file and use them ?
thank you
Jan
					
				
			
			
				
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
I try telnet on multiple host with perl. Hosts are stored in hosts.txt but I don't now how to use them. (I can only use ARGV[0] from line)
telnet.pl 10.3.0.29
----
#!/usr/bin/perl
use strict;
use Net::Telnet ();
my $host = $ARGV[0];
my $username = "user";
my $password = "passwd";
my $conn = new Net::Telnet (Timeout => 1,
Errmode => 'return',
);
$conn->open($host);
$conn->login($username,$password);
print $conn->cmd('uname -a');
$conn->close();
-----
I tried
for ($i = 0; `cat hosts.txt`; ++$i) but it doesn't work.
How can I retrive hosts form file and use them ?
thank you
Jan
	GSM, Intelligent Networks, UNIX
			
			
				Solved! Go to Solution.
		3 REPLIES 3
	
	            
            
		
		
			
            
                - Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2004 11:52 PM
09-14-2004 11:52 PM
Solution
			
				
					
					
						Hello Jan,
You can retrieve the content the file using the following method.
#!/usr/bin/perl
use strict;
use Net::Telnet ();
open(FILE, "telnet.txt") or die("Unable to open file");
@data =;
$ending_value = scalar(@data);
for($counter=0 ; $counter < $ending_value ; $counter++)
{
my $host = $data[$counter];
my $username = "user";
my $password = "passwd";
my $conn = new Net::Telnet (Timeout => 1,Errmode => 'return',);
$conn->open($host);
$conn->login($username,$password);
print $conn->cmd('uname -a');
$conn->close();
}
close(FILE);
use appropriate username and password.
NOTE: You should have installed the Net/Telnet.pm Perl module in your system
Regards,
Senthil Murugan
 
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
You can retrieve the content the file using the following method.
#!/usr/bin/perl
use strict;
use Net::Telnet ();
open(FILE, "telnet.txt") or die("Unable to open file");
@data =
$ending_value = scalar(@data);
for($counter=0 ; $counter < $ending_value ; $counter++)
{
my $host = $data[$counter];
my $username = "user";
my $password = "passwd";
my $conn = new Net::Telnet (Timeout => 1,Errmode => 'return',);
$conn->open($host);
$conn->login($username,$password);
print $conn->cmd('uname -a');
$conn->close();
}
close(FILE);
use appropriate username and password.
NOTE: You should have installed the Net/Telnet.pm Perl module in your system
Regards,
Senthil Murugan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2004 11:53 PM
09-14-2004 11:53 PM
			
				
					
						
							Re: perl telnet on multiple host
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Hi, 
you can do:
unless (open(FILE, $hostfile)) {
print STDERR "Can't open $hostfile\n";
return;
}
while (my $host =) {
chop($host);
....
here your code
....
} 
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
you can do:
unless (open(FILE, $hostfile)) {
print STDERR "Can't open $hostfile\n";
return;
}
while (my $host =
chop($host);
....
here your code
....
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2004 01:23 AM
09-15-2004 01:23 AM
			
				
					
						
							Re: perl telnet on multiple host
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						thanks, it works fine ;-) 
Only my() funct. had to be added
#!/usr/bin/perl
use strict;
use Net::Telnet ();
open(FILE, "hosts.txt") or die("Unable to open hosts.txt ");
my @hosts =;
my $ending_value = scalar(@hosts);
for(my $counter=0 ; $counter < $ending_value ; $counter++)
{
my $host = $hosts[$counter];
my $username = "user";
my $password = "passwd";
my $conn = new Net::Telnet (Timeout =>1,
Errmode => 'return',);
$conn->open($host);
$conn->login($username,$password);
print $conn->cmd('uname -a');
$conn->close();
}
close(FILE); 
					
				
			
			
				
		
		
	
	
	
Only my() funct. had to be added
#!/usr/bin/perl
use strict;
use Net::Telnet ();
open(FILE, "hosts.txt") or die("Unable to open hosts.txt ");
my @hosts =
my $ending_value = scalar(@hosts);
for(my $counter=0 ; $counter < $ending_value ; $counter++)
{
my $host = $hosts[$counter];
my $username = "user";
my $password = "passwd";
my $conn = new Net::Telnet (Timeout =>1,
Errmode => 'return',);
$conn->open($host);
$conn->login($username,$password);
print $conn->cmd('uname -a');
$conn->close();
}
close(FILE);
	GSM, Intelligent Networks, UNIX
			
			
				
			
			
			
			
			
			
		The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP
