in reply to Re^3: Need help with Perl multi threading
in thread Need help with Perl multi threading
produces this output:#!/usr/bin/perl use threads; use strict; use warnings; use Net::SSH::Expect; require 'total.pl'; my @servers = ('192.168.0.18','192.168.0.19','192.168.0.20'); my @process = ('testing','b','c'); my @threads; my $output; my $res; my $final; #@output = threads->new(\&Process_Output, $ssh, $proc )->join(); foreach my $host ( @servers ) { threads->new(\&process, $host )->join(); } sub process() { my $host = shift; my $png = `ping -c1 $host`; if ( $png =~ /64 bytes/ ) { my $user= 'netcool'; my $ssh = &SSH_Reference($host,$user); $ssh->run_ssh(); eval {$res=$ssh->read_all(); }; if ( !$@ && $res !~ /\(yes\/no\)/ && $res !~ m/password/ ) { print "\nLogged in to $host\n"; foreach my $proc ( @process ) { #push (@threads, threads->new(\&Process_Output, $s +sh, $proc )); $output=&Process_Output($ssh, $proc ); #print @output; if ( $output =~ m/$proc/ ) { print "\t$proc is runn +ing\n"; } else { print "\t$proc is not +running\n"; } } $ssh->close(); } else { print "Unable to SSH to $host\n"; } } else { print "\nUnable to ping to Host: $host\n"; } }
Now again back to the stage where I have started my script....perl some.pl Unable to SSH to 192.168.0.18 Unable to SSH to 192.168.0.19 Unable to SSH to 192.168.0.20
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Need help with Perl multi threading
by chromatic (Archbishop) on Jan 25, 2012 at 23:36 UTC | |
by ashok.g (Beadle) on Jan 27, 2012 at 11:55 UTC | |
by chromatic (Archbishop) on Jan 27, 2012 at 20:09 UTC | |
by ashok.g (Beadle) on Jan 30, 2012 at 16:35 UTC | |
by BrowserUk (Patriarch) on Jan 30, 2012 at 17:01 UTC |