Untested as I don't have access to multiple telnet hosts, but it should work correctly.
The Net::Telnet stuff is based entirely on your sample. I never used it, nor even read the manual.
If you're dealing with more than a half a dozen or so threads, it would be better to use a fixed size pool rather than one per... That's slightly more complicated, but only slightly.
#! perl -slw use strict; use threads qw[ async ]; use Net::Telnet; sub remoteCmd { my( $host, $user, $pass, @cmds ) = @_ my $t = new Net::Telnet( Timeout => 2810, Prompt => '/%/', Host => $host ); $t->login( $user, $pass ); $t->cmd( $_ ) for @cmds; $t->close; } my @hosts = ( [ qw[ 111.111.111.001 user pass ] ], [ qw[ 111.111.111.002 user pass ] ], [ qw[ 111.111.111.003 user pass ] ], [ qw[ 111.111.111.004 user pass ] ], [ qw[ 111.111.111.005 user pass ] ], [ qw[ 111.111.111.006 user pass ] ], [ qw[ 111.111.111.007 user pass ] ], ); my @cmds = ( 'cd ~', 'ls -l' ); ## These three lines do all the work. my $count : shared = @hosts; async{ remoteCMD( @$_, @cmds ); $count-- }->detach for @hosts; sleep 1 while $count--;
In reply to Re: run command on multiple hosts (use threads;)
by BrowserUk
in thread run command on multiple hosts
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |